After completing portfolio, page loads a black page. I'm king of lost when needs to display in HTML/PHP/CSS code. xyz_form is understood. See portfolio (view) code below. CSS format took from Google.
1 Answer
Looks like you mixed and matched the controller (C of MVC), and the view (V of MVC). Ideally, you want the controller to render the page to be viewed (let's call it portfoliopage.php). Controller will have the code, which should query mysql for the stocks held and store them in $positions array. You do not query mysql in your code above, which is why you are getting an empty $positions array. You can then use render function to pass $positions to portfoliopage.php. Portfoliopage.php, meanwhile, will contain all the html, including the table format, which is this part in your code above:
<?php
foreach ($positions as $position)
{
print("<tr>");
print("<td>{$position["symbol"]}</td>");
print("<td>{$position["name"]}</td>");
print("<td>{$position["shares"]}</td>");
print("<td>{$position["price"]}</td>");
print("<td>{$position["total"]}</td>");
print("</tr>");
}
?>
Also, your background formatting will not work as written above, you might want to consider using css for this.
-
"You do not query mysql in your code above" Where am I query mysql above? On the other hand, how can I connect "Portfoliopage.php" (view) to index.php (controller)? Watching shorts about MVC don't explain it. Commented Apr 25, 2016 at 14:05
-
What you want to do is split what you have above into 2 separate files, the controller, which we'll call index.php, and the page to be viewed, which we'll call portfoliopage.php. Controller will query mysql for the stocks held, and hold the data in $positions array, assigning values to keys ("symbol", "shares", etc.) much like you already have above. You will then pass $positions to portfoliopage.php via render function. It is portfoliopage.php which will contain the html that the user will see.– rongaCommented Apr 26, 2016 at 5:15