Skip to content

Instantly share code, notes, and snippets.

@svolpe43
Created April 2, 2014 00:31
Show Gist options
  • Save svolpe43/9925837 to your computer and use it in GitHub Desktop.
Save svolpe43/9925837 to your computer and use it in GitHub Desktop.
Leaderboard controller
$userinfos = query("SELECT * FROM users ORDER BY cash DESC");
if ($userinfos === false)
{
apologize("Couldn't load your data.");
}
$positions = [];
$rank = 1;
//Cycle through each user
foreach ($userinfos as $userinfo)
{
$stocktotal = 0;
dump($userinfos);
$portfolios = query("SELECT * FROM portfolio WHERE ?", $userinfo["id"]);
//Cycle through each stock
foreach ($portfolios as $portfolio)
{
$thisstock = 0;
$stock = lookup($portfolio["symbol"]);
$thisstock = $stock["price"] * $portfolio["shares"];
$stocktotal += $thisstock;
}
$positions[] = [
"rank" => $rank,
"name" => $userinfo["username"],
"cash" => $userinfo["cash"],
"stocktotal" => $stocktotal
];
$rank++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment