<?php
// (C) 2000 LinuxFutures.com, Inc.
//
// Part of UPmarkets - the software behind the LinuxFutures game site
// visit www.LinuxFutures.com to play
//
// We are making the software available to you under the GNU General Public License,
// a copy of which should accompany this software in the file LICENSE.
//
// A web-based copy of the LICENSE is located at http://www.gnu.org/copyleft/gpl.txt
//
// While there is no charge for using this software, there are important restrictions.
//
// This LICENSE does not allow, in general, proprietary modifications or proprietary derivative works.
// If you base new commercial products on our work, great, but you have to give them away just as we did.
//
// This software carries ABSOLUTELY NO WARRANTY. It is offered AS-IS, and may not work at all
// or may have harmful or hazardous side effects.
//
//
// -------------------- what this file does ---------------------
// provides function last_prices_array()
// which returns an array giving the prices for each symbol
// if called with no arguments or 0, gives all prices
// if called with a userid number, gives prices relevant to that user's holdings
//
function last_prices_array($userid = "0") {
global $db_link;
$userid = (int) $userid;
if ($userid == 0) {
$sql = "SELECT DISTINCT symbols.symbol as symbol, pricings.price as price ";
$sql .= " from symbols, pricings, pricings_latest ";
$sql .= " WHERE symbols.symbolid = pricings.symbolid ";
$sql .= " AND symbols.symbolid = pricings_latest.symbolid ";
$sql .= " AND pricings_latest.posted = pricings.posted ";
$sql .= " ORDER BY symbols.symbolid ASC;";
} else {
$sql = "SELECT DISTINCT symbols.symbol as symbol, pricings.price as price ";
$sql .= " from symbols, pricings, pricings_latest, ledgers ";
$sql .= " WHERE symbols.symbolid = pricings.symbolid ";
$sql .= " AND symbols.symbolid = pricings_latest.symbolid ";
$sql .= " AND symbols.symbolid = ledgers.symbolid ";
$sql .= " AND pricings_latest.posted = pricings.posted ";
$sql .= " AND ledgers.userid = ".$userid." ";
$sql .= " ORDER BY symbols.symbolid ASC;";
}
$r = mysql_query($sql, $db_link);
mysql_error_sanity("f_last_prices_array.inc ".$sql);
$N = mysql_num_rows($r);
$lpa = array();
for( $i = 0; $i < $N ; $i++ ) {
$symbol = mysql_result($r,$i,"symbol");
$price = mysql_result($r,$i,"price");
$lpa[$symbol] = $price;
}
mysql_free_result($r);
return($lpa);
}
?>