Hey everyone im tryin to code something which may be simple but ive attempted and failed. Im creating a stock market simulation website using php and phpmyadmin. In the table JAME_PH i have this-
id symbol shares volume price
53 JAME 0 50.00
I now want to do price change, ive already gotten volume to change and work (the sum of all shares) but now i would like the price to change due to volume .01% at a time, so it would really be a .01% change for every 10 shares traded. I'm lost on how to do this calculatio in php. below i started some code think i was goin in the right direction... all help is appreciated!!!!
here is the code on my buy page as of now
PHP Code:
<html> <body> Go Back to<a href="index.php">Your Portfolio</a> <br> <br> Are you sure you want to buy shares in JAME? (Total Below) <br> <br> <?php ob_start(); include("config.php"); $username = $_COOKIE['loggedin']; if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=../login.html>click here</a> to login."); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $get_my_basket = mysql_query("SELECT `symbol`, `price` FROM `JAME_PH` WHERE `symbol`='".JAME."'"); $total_cost = 0; $JAME = 0; $quantity = $_POST['quantity']; while($my_basket = mysql_fetch_array($get_my_basket)) { if($my_basket['symbol']=='JAME') $JAME++; $total_cost += $my_basket['price'] * $quantity; } echo 'You have selected: '; if($JAME > 0) { echo $quantity.' JAME shares, '; } else { echo 'Your Basket it Empty'; } $total_cost = number_format($total_cost,2); echo ' and it will cost you $'.$total_cost; $query = "select `shares` from JAME_PH"; $result = mysql_query($query); $volume = $_POST['quantity']; while($row = mysql_fetch_array($result)) { $volume += (int)$row['shares']; echo 'id '.$row['id']; echo 'symbol '.$row['symbol']; echo 'shares '.$row['shares']; // add to the volume and print echo 'volume = '.$volume; echo 'price = '.$row['price']; }
// I want to make a new query and new result here
$query2 = "select `price` from JAME_PH WHERE `id`=53"; $result2 = mysql_query($query); $price= 50.00; while($row = mysql_fetch_array($result2)) { // SO LOST ON WHERE TO BEGIN. i want it so every time a user trades(buys) 10 shares the price (50.00) will increase by .01% - so when someone buys 10 shares 50.00 will change to 50.05
// 50.00 * .01 = 0.5 now add the .5 to 50.00 to get 50.05 and insert into the table at id 53 under price!!!. I wish i new where to begin. THANKS IN ADVANCE ANYONE!!!!! }
$insert = mysql_query("insert into trades values ('NULL', 'JAME', '".$_POST['quantity']."', '$total_cost', '$username' )") or die("Could not insert data because ".mysql_error()); $insert2 = mysql_query("insert into JAME_PH values ('NULL', 'JAME', '".$_POST['quantity']."', $volume, '$username',$increase, '$username' )") or die("Could not insert data because ".mysql_error()); ob_end_flush(); ?> <br> <br> Visit<a href="index.php">Your Portfolio</a> to see your purchases. </body> </html
Last edited by jcrensha627; 04-08-2009 at 08:28 PM..
Reason: addition
|