MemphiS Posted June 9, 2007 Share Posted June 9, 2007 I wish to retrieve all data from a column which is called "cost" Example: $query = mysql_query("SELECT `cost` FROM `table` WHERE `id` = '1'"); // 10 users may have the id "1" while ($getcost = mysql_fetch_row($query)){ $start = 0; $overall = $start += $getcost[0]; } echo "$overall"; Problem is it only gets the last record in the table instead of adding all the values together Anyone have a solution Thanks Link to comment https://forums.phpfreaks.com/topic/54870-sql-question/ Share on other sites More sharing options...
chigley Posted June 9, 2007 Share Posted June 9, 2007 Quicker way: $query = mysql_query("SELECT SUM(cost) FROM table WHERE id = 1") or die(mysql_error()); Alternatively put start = 0 before the while. Link to comment https://forums.phpfreaks.com/topic/54870-sql-question/#findComment-271358 Share on other sites More sharing options...
MemphiS Posted June 9, 2007 Author Share Posted June 9, 2007 Thanks chigley Link to comment https://forums.phpfreaks.com/topic/54870-sql-question/#findComment-271361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.