Advertisement
tironci84

Portfolio

Mar 26th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. portfolio.php file
  2.    
  3.     <table class="table table-hover center-table table-bordered">
  4.             <tr>
  5.             <th>Symbol</th>
  6.             <th>Name</th>
  7.             <th>Shares</th>
  8.             <th>Price</th>
  9.             <th>Total</th>
  10.             </tr>
  11.     <?php foreach ($shares as $row): ?>
  12.              
  13.             <tr>
  14.             <td><?= $row["symbol"]?></td>
  15.             <td><?= $row["name"]?></td>
  16.             <td><?= $row["shares"]?></td>
  17.            
  18.             <td id="price">$<?= number_format($row["price"],2)?></td>
  19.            
  20.             <td>$<?= number_format($row["total"],2)?></td>
  21.             </tr>
  22.        
  23.     <? endforeach ?>
  24.    
  25.    
  26.    
  27.     <tr>
  28.         <td>CASH</td>
  29.         <td></td>
  30.         <td></td>
  31.         <td></td>
  32.         <td>$<?= number_format($cash[0]["cash"], 2)?></td>
  33.        
  34.     </tr>
  35.    
  36.     </table>
  37.  
  38. <script type="text/javascript" src="js/update.js" ></script>
  39.  
  40. index.php file
  41.  
  42. <?php
  43.  
  44.     // configuration
  45.     require("../includes/config.php");
  46.  
  47.     //query user's portfolio
  48.    
  49.     $rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
  50.     $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
  51.    
  52.         //create array to store the shares
  53.         $shares = [];
  54.        
  55.         //for each of the user info
  56.        
  57.         foreach($rows as $row){
  58.            
  59.             //lookup stock info
  60.             $stock = lookup($row["symbol"]);
  61.            
  62.            
  63.             if($stock !== false){
  64.                
  65.                 $shares[] = [
  66.                     "name" => $stock["name"],
  67.                     "price" => $stock["price"],
  68.                     "shares" => $row["shares"],
  69.                     "symbol" => $row["symbol"],
  70.                     "total" => $row["shares"]*$stock["price"]
  71.                    
  72.                 ];
  73.                      //dump($shares);      
  74.             }
  75.            
  76.         }
  77.        
  78.     // render portfolio
  79.     render("portfolio.php", ["shares" => $shares,"cash" => $cash, "title" => "Portfolio"] );  
  80. ?>
  81.  
  82. update.php
  83.  
  84. <?php
  85.  
  86.     require("../includes/functions.php");
  87.     require("../includes/config_update.php");
  88.    
  89.     $rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
  90.     $cash = query("SELECT cash FROM users WHERE id = ?", $_SESSION["id"]);
  91.             //create array to store the shares
  92.         $shares = [];
  93.        
  94.         //for each of the user info
  95.        
  96.         foreach($rows as $row){
  97.        
  98.             $stock = lookup($row["symbol"]);
  99.            
  100.             if($stock !== false){
  101.                
  102.                 $shares[] = [
  103.                    
  104.                     "name" => $stock["name"],
  105.                     "price" => $stock["price"],
  106.                     "shares" => $row["shares"],
  107.                     "symbol" => $row["symbol"],
  108.                     "total" => $row["shares"]*$stock["price"]
  109.                 ];
  110.                     //dump($share[0]["price"]);        
  111.             }
  112.         }
  113.                
  114.     // render portfolio
  115.     render("portfolio.php", ['shares' => $shares, 'cash' => $cash, 'title' => "Portfolio"]);  
  116. ?>
  117.  
  118.  
  119. update.js
  120.  
  121.   $(document).ready(function(){
  122.         var updater = setTimeout(function(){
  123.             $('#price').load('update.php', 'update=true');
  124.         },6);
  125.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement