here is my situation i am making a sort of stock market simulation phpsql site. this current page and code below is my purchasing page. I am having trouble coming up with volume, below i tried using
id symbol shares volume price increase time
53 JAME 0 50.00
i am using the `price` and `symbol` in the table above to get $total_cost. THANKS in advance to any replies, my code and error is below.
- Warning: Invalid argument supplied for foreach() in /mounted-storage/home59c/sub007/sc37816-TACW/www/members/conflebronjames.php on line <b>52
here is my code for the page below
Code: Select all
<?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.");
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
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;
//code i received from someone on the net to come up with volume.
$query = "select * from JAME_PH where symbol = 'JAME' ";
$result = mysql_query($query);
$volume = 0;
foreach($result as $key => $row)
{
echo 'id '.$row['id'];
echo 'symbol '.$row['symbol'];
echo 'shares '.$row['shares'];
// add to the volume and print
echo 'volume = '.$volume = $volume + $row['shares'] ;
echo 'price = '.$row['price'];
}
$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','$total_cost', '$username' )")
or die("Could not insert data because ".mysql_error());
ob_end_flush();
?>