Right now, everything except cash in my portfolio implementation seems to be working well. The cash value, however, seems to report only the first digit of a user's cash balance. (For example, a $10,000 cash balance displays as 1, a $5,555 value displays as 5.)
Here is the index side:
$positions = [];
$rows = CS50::query("SELECT Symbol, Shares from portfolio_real WHERE id=?", $_SESSION["id"]);
foreach ($rows as $row)
{
$stock = lookup($row["Symbol"]);
if ($stock !== false)
{
$positions[] = [
"name" => $stock["name"],
"price" => $stock["price"],
"shares" => $row["Shares"],
"symbol" => $row["Symbol"],
"total"=>$row["Shares"] * $stock["price"]
];
}
}
$users= CS50::query("SELECT * FROM users WHERE id=?", $_SESSION["id"]);
$cash=$users[0]["cash"];
// render portfolio
render("portfolio.php", ["positions"=>$positions, "title"=>"Portfolio", "cash"=>$cash]);
And the portfolio side:
<tr>
<td align="left", colspan="4">CASH</td>
<td align="left"><?= $cash[0] ?></td>
</tr>