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"]); 

// render portfolio
render("portfolio.php", ["positions"=>$positions, "title"=>"Portfolio", "cash"=>$cash]);

And the portfolio side:

    <td align="left", colspan="4">CASH</td>
    <td align="left"><?= $cash[0] ?></td>

1 Answer 1


Instead of

<td align="left"><?= $cash[0] ?></td>


<td align="left"><?php echo $cash; ?></td>
  • Thank you! It displays accurately with this edit. I'm curious, though, if the problem was a lack of php delimiters or if I needed echo - any thoughts? Thank you again!
    – Cchio
    Jul 11, 2016 at 20:43
  • Both, and also, you were trying to access 1st element of $cash associative array when in fact $cash is not defined as an array and only holds a single numeric value.
    – ronga
    Jul 12, 2016 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .