Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.     // configuration
  3.     require("../includes/config.php");  
  4.    
  5.     $id = $_SESSION["id"];
  6.     $portfolios_info = CS50::query("SELECT * FROM Portfolios");
  7.     $rows = CS50::query("SELECT symbol, shares FROM Portfolios WHERE user_id = ?", $portfolios_info[0]["user_id"]);
  8.                
  9.     $positions = [];
  10.     foreach ($rows as $row)
  11.     {
  12.       $stock = lookup($row["symbol"]);
  13.       if ($stock !== false)
  14.       {
  15.           $positions[] = [
  16.           "name" => $stock["name"],
  17.           "price" => $stock["price"],
  18.           "shares" => $row["shares"],
  19.           "symbol" => $row["symbol"],
  20.           "total" => sprintf("%.2f", $row["shares"] * $stock["price"])
  21.           ];
  22.       }
  23.     }
  24.      
  25.     $cash = CS50::query("SELECT cash FROM users WHERE id = $id");
  26.     // render portfolio
  27.     render("portfolio.php", ["title" => "Positions", "positions" => $positions, "cash" => $cash]);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement