Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- portfolio.php file
- <table class="table table-hover center-table table-bordered">
- <tr>
- <th>Symbol</th>
- <th>Name</th>
- <th>Shares</th>
- <th>Price</th>
- <th>Total</th>
- </tr>
- <?php foreach ($shares as $row): ?>
- <tr>
- <td><?= $row["symbol"]?></td>
- <td><?= $row["name"]?></td>
- <td><?= $row["shares"]?></td>
- <td id="price">$<?= number_format($row["price"],2)?></td>
- <td>$<?= number_format($row["total"],2)?></td>
- </tr>
- <? endforeach ?>
- <tr>
- <td>CASH</td>
- <td></td>
- <td></td>
- <td></td>
- <td>$<?= number_format($cash[0]["cash"], 2)?></td>
- </tr>
- </table>
- <script type="text/javascript" src="js/update.js" ></script>
- index.php file
- <?php
- // configuration
- require("../includes/config.php");
- //query user's portfolio
- $rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
- $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
- //create array to store the shares
- $shares = [];
- //for each of the user info
- foreach($rows as $row){
- //lookup stock info
- $stock = lookup($row["symbol"]);
- if($stock !== false){
- $shares[] = [
- "name" => $stock["name"],
- "price" => $stock["price"],
- "shares" => $row["shares"],
- "symbol" => $row["symbol"],
- "total" => $row["shares"]*$stock["price"]
- ];
- //dump($shares);
- }
- }
- // render portfolio
- render("portfolio.php", ["shares" => $shares,"cash" => $cash, "title" => "Portfolio"] );
- ?>
- update.php
- <?php
- require("../includes/functions.php");
- require("../includes/config_update.php");
- $rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
- $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
- //create array to store the shares
- $shares = [];
- //for each of the user info
- foreach($rows as $row){
- $stock = lookup($row["symbol"]);
- if($stock !== false){
- $shares[] = [
- "name" => $stock["name"],
- "price" => $stock["price"],
- "shares" => $row["shares"],
- "symbol" => $row["symbol"],
- "total" => $row["shares"]*$stock["price"]
- ];
- //dump($share[0]["price"]);
- }
- }
- // render portfolio
- render("portfolio.php", ['shares' => $shares, 'cash' => $cash, 'title' => "Portfolio"]);
- ?>
- update.js
- $(document).ready(function(){
- var updater = setTimeout(function(){
- $('#price').load('update.php', 'update=true');
- },6);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement