ultraloveninja Posted February 21, 2010 Share Posted February 21, 2010 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 More sharing options...
ultraloveninja Posted February 21, 2010 Author Share Posted February 21, 2010 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 />"; Link to comment https://forums.phpfreaks.com/topic/192848-adding-single-result-row/#findComment-1015789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.