ukweb Posted December 13, 2006 Share Posted December 13, 2006 Hi there.I am developing a php based program to invoice people, I got a really basic one for you here but I can't for the life of me remember how I did it last time!.The query selects all outstanding records from an invoice table for a specific user. One of the columns is 'cost'. I want to add all the values of the 'cost' column from the results in the query. How do I do this? many thanksStephen Link to comment https://forums.phpfreaks.com/topic/30478-add-all-values-of-a-column-in-a-query/ Share on other sites More sharing options...
Round Posted December 13, 2006 Share Posted December 13, 2006 try$sql = "select sum(cost) as total from invoices where record =\"$oustanding\" and user = \"$user\" "; $num= mysql_num_rows ($rs); if ($num !=0) {$row = mysql_fetch_array( $rs ); $total = row["total"]; } else { $total = 0; }tweak to suit Link to comment https://forums.phpfreaks.com/topic/30478-add-all-values-of-a-column-in-a-query/#findComment-140334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.