Created
April 2, 2014 00:31
-
-
Save svolpe43/9925837 to your computer and use it in GitHub Desktop.
Leaderboard controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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