0

Hi,

I want to output a simple result. I join 2 tables and SUM one column in one, i get the SUM results correct but cannot get the num_rows proper.

My Code:

$clientid = 24;

$query = "SELECT items.itemid, SUM(prices.priceid) as PR FROM items 
JOIN prices ON items.itemid = prices.itemid 
WHERE items.clientid = '$clientid'";


$result =  $db_connect -> query($query);
$row_cnt = $result -> num_rows; 

echo $joinrow_cnt."<br/><br/><br/>";

while($assocresult = mysqli_fetch_assoc($result)){

    $price = $assocresult['price'];
    $sumprice = $assocresult['PR'];
    $item = $assocresult['itemid'];
    $realprice = ($price/100)*80;        //after 80% discount

    echo "ItemId: ".$item." Price : " .$price." real price: " .$realprice."<br/>";
    echo "Sum of all items: " .$sumprice;

}

I only get one line of result and the $row_cnt value is only 1.

I want to be able to display the number of rows where items.clientid = '$clientid' and want to SUM(prices.priceid).

P.S. The column 'priceid' contains the actual price.

Thanks in advance !!

2
Contributors
1
Reply
20
Views
2 Years
Discussion Span
Last Post by cereal
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.