Jump to content

Adding single result row


ultraloveninja

Recommended Posts

I am trying to figure out how to add the result of a single row from a mysql select but I just can't seem to wrap my head around it.

 

Here's what I have:

$sql = "select ct_qty from tbl_cart";
$result = mysql_query($sql);
  while ($row = mysql_fetch_array($result)) {
       $qty = $row['ct_qty'];

  }
echo "QTY: $qty <br /><br />";

 

which will return the result like this:

 

QTY: 1 

QTY: 3

 

 

But I just can't remember how to add those two numbers together.

 

 

Link to comment
https://forums.phpfreaks.com/topic/192848-adding-single-result-row/
Share on other sites

HA!!!!

I found it!!!!

 

 

Here's how I got it to work:

 



$sql = "select ct_qty from tbl_cart";
$result = mysql_query($sql);
$total_count = 0;
  while ($row = mysql_fetch_array($result)) {
       $total_count += $row['ct_qty'];

  }
  mysql_free_result($result);
echo "QTY: $total_count <br /><br />";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.