Hi,
I have a table (sales) with 3 columns(id,name,price) the price column is integer,
I have two records ;
id = 1 name = Car price = 10000 id = 2 name = Car 2 price = 15000
I want to calculate the (price) columns in which the total = 25000?
Thanks
you want to work out how many rows contian 25000?
something along the lines of
$conn = your connection code $sql = "select * from sales where price= '25000'; $rs = mysql_query( $sql, $conn ) or die ( "Could not execute query" ); $total= mysql_numrows( $rs ); echo $total;
FireLight wrote:you want to work out how many rows contian 25000? something along the lines of $conn = your connection code $sql = "select * from sales where price= '25000'; $rs = mysql_query( $sql, $conn ) or die ( "Could not execute query" ); $total= mysql_numrows( $rs ); echo $total;
I want to calculate the price rows total ?
if you just want the total of all sales with no criteria
select sum(price) as revenue from sales;
But your description is unclear. What is the 25,000 for?
This is the general idea
<?php $conn = your connection code $sql = "select 'price' from sales "; $rs = mysql_query( $sql, $conn ) or die ( "Could not execute query" ); while($row = mysql_fetch_array($rs)) //loops through all rows { $Total = Total + $row['price']; //adds 'price' from that row to the variable total } echo ($Total); ?>
25,000 is the total of the rows in price,
FireLight : I will try, thanks !