rendered paste body <center> <a href="index.php?action=1">To add an entry, click here.</a><br> <a href="index.php?action=2">To view past entries, click here.</a><br> <a href="index.php?action=3">To edit past entries, click here.</a><br><br> </center> <? include('database.php'); /*NEW ENTRY FORM ****************/ if ($_REQUEST['action'] == 1) { ?> <center> <form action="adder.php" method="GET"> Investor Name <select name="investor_name" height="5" width="10"> <option value="Alex">Alex</option> <option value="Cody">Cody</option> </select><br> Stock Symbol <input name="stock_symbol" size="5"><br> Shares Traded <input name="num_shares" size="5"><br> Bought <input name="price_bought" size="5"><br> Sold <input name="price_sold" size="5"><br> <input type="submit"> </form> </center> <? } /*VIEW ENTRIES *****************/ if ($_REQUEST['action'] == 2) { $result = mysql_query("SELECT * FROM records"); while($row = mysql_fetch_array($result)) { ?> <center> <a href="index.php?action=3&id=<? echo $row['id']; ?>">Edit</a> <a href="index.php?action=4&id=<? echo $row['id']; ?>">View</a> <? echo $row['id'] . " " . $row['investor_name'] . " " . $row['stock_symbol'] . " " . $row['price_bought'] . " " . $row['price_sold']; } } /*EDIT ENTRIES **************/ if ($_REQUEST['action'] == 3) { $result = mysql_query("SELECT * FROM records"); while($row = mysql_fetch_array($result)) { echo "<center></center>"; } } /*VIEW ENTRY BASED ON ID ***************************/ if ($_REQUEST['action'] == 4 && !empty($_REQUEST['id'])) { $theid = $_REQUEST['id']; $result = mysql_query("SELECT * FROM records WHERE id = '$theid'"); while($row = mysql_fetch_array($result)){ $bought = $row['price_bought']; $sold = $row['price_sold']; $gain_loss_perc = $sold / $bought; echo "<center>"; echo "<table>"; echo "<tr><td>Investor Name:</td><td>" . $row['investor_name'] . "</td></tr>"; echo "<tr><td>Stock Symbol:</td><td>" . $row['stock_symbol'] . "</td></tr>"; echo "<tr><td>Shares Traded:</td><td>" . $row['num_shares'] . "</td></tr>"; echo "<tr><td>Bought:</td><td>$" . $row['price_bought'] . "</td></tr>"; echo "<tr><td>Sold:</td><td>$" . $row['price_sold'] . "</td></tr>"; echo "<tr><td>Gain/Loss %:</td><td>%<font color='"; if($bought > $sold){ $gl_color = red; }elseif($bought < $sold){ $gl_color = green; }elseif($bought == $sold){ $gl_color = gray; } echo $gl_color . "'>"; function round_up($value, $places=0){ if($places < 0){ $places = 0; } $mult = pow(10, $places); return ceil($value * $mult) / $mult; } echo round_up($gain_loss_perc, 2); echo "</font></td></tr>"; echo "</table>"; } }?>