Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // configuration
- require("../includes/config.php");
- $id = $_SESSION["id"];
- $portfolios_info = CS50::query("SELECT * FROM Portfolios");
- $rows = CS50::query("SELECT symbol, shares FROM Portfolios WHERE user_id = ?", $portfolios_info[0]["user_id"]);
- $positions = [];
- 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" => sprintf("%.2f", $row["shares"] * $stock["price"])
- ];
- }
- }
- $cash = CS50::query("SELECT cash FROM users WHERE id = $id");
- // render portfolio
- render("portfolio.php", ["title" => "Positions", "positions" => $positions, "cash" => $cash]);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement