Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index.php:
- <?php
- // configuration
- require("../includes/config.php");
- $positions = [];
- $rows = CS50::query("SELECT shares, symbol FROM portfolios WHERE user_id = ?", $_SESSION["id"]);
- $cash = CS50::query("SELECT cash FROM users 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"]
- ];
- }
- }
- // render portfolio
- render("portfolio.php", ["positions" => $positions, "cash" => $cash, "title" => "Portfolio"]);
- ?>
- portfiolio.php:
- <div>
- <table class="table table-striped table-hover">
- <?php foreach ($positions as $position): ?>
- <thead>
- <th>Symbol</th>
- <th>Name</th>
- <th>Shares</th>
- <th>Price</th>
- <th>TOTAL</th>
- </thead>
- <tbody>
- <tr>
- <td><?= $position["symbol"] ?></td>
- <td><?= $position["name"] ?></td>
- <td><?= $position["shares"] ?></td>
- <td>$<?= $position["price"] ?></td>
- <td>$<?= $position["total"] ?></td>
- </tr>
- <tr>
- <td colspan="4">CASH</td>
- <td>$<?= $cash[0]["cash"] ?></td>
- </tr>
- </tbody>
- <?php endforeach ?>
- </table>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement