Been stuck on this problem for the last few hours, in order to implement portfolio I started by practicing, the idea was to call skroob's column of symbol, lets say I manually added two symbols there and than using a loop, call lookup for each symbol and print out the price, name and symbol through the portfolio.php file. I kind of know a bit why I am getting this error but would appreciate if someone much further explain it to me why am I getting this and most importantly how to do what I have explained I want to do
code for index.php
<?php // configuration require("../includes/config.php"); $positions = []; $rows = CS50::query ("SELECT symbol FROM portfolios WHERE user_id = ?", $_SESSION["id"]); // lookup for quotes for every symbol foreach ($rows as $row) { $stock = lookup($row); $positions = ["name" => $stock["name"], "price" => number_format($stock["price"], 2, '.', ''), "symbol" => $stock["symbol"]]; } // render portfolio render("portfolio.php", ["title" => "Portfolio", "positions" => $positions]); ?>
code for portfolio.php
<div>
foreach ($positions as $position) { print("<tr>"); print("<td>{$positions["symbol"]}</td>"); print("<td>{$positions["name"]}</td>"); print("<td>{$positions["price"]}</td>"); print("</tr>"); } ?>