The script:
PHP Code:
<?php
require_once("lib.php");
update_rankings();
$query = "INSERT INTO cronJobUpdates (type) VALUES ('rankings')";
mysql_query($query);
?>
and the function inside lib.php it calls:
PHP Code:
//will update the rankings in the DB
function update_rankings() {
//get an array of all the portfolios as Portfolio objects
$portfolios = get_portfolios();
if (isset($portfolios)) {
//delete the old rankings and save the new ones
$query = "DELETE FROM rankings WHERE 1=1";
mysql_query($query) or die("Error deleting old rankings: ".mysql_error());
//for each one of the portfolios...
foreach ($portfolios as $port) {
//give the script more time to finish
set_time_limit(30);
$info = $port->get_info();
$totals = $port->get_totals($info);
$netWorth = $totals['mktValue'] + $port->cash;
$query = "INSERT INTO rankings (uid, comp_id, netWorth)
VALUES ('".$port->uid."', '".$port->comp->id."', '".$netWorth."')";
mysql_query($query) or die ("Insert failed: ".mysql_error());
}
}
}
Bookmarks