billhobbs Posted June 2, 2012 Share Posted June 2, 2012 I have a page that repeats a table from my database. I add to fields from the table together to get a combined value with a a session name $charge . This table is repeated based on a common id. I need to add the $charge from each displayed fields to create another session variable called $totalcharges . How do I do this? Link to comment https://forums.phpfreaks.com/topic/263522-add-session-variable-from-repeat-fields/ Share on other sites More sharing options...
billhobbs Posted June 2, 2012 Author Share Posted June 2, 2012 Here is a pic of what I'm trying to do. $charge = $200.00 -- this is created by multiplying 2 other variables together $charge = $500.00 -- this is created by multiplying 2 other variables together Total charge should be $700.00 I can't use sum($charge) like I would normally do when I add fields from the database. How do I add the 2 $charge values together? Link to comment https://forums.phpfreaks.com/topic/263522-add-session-variable-from-repeat-fields/#findComment-1350514 Share on other sites More sharing options...
Drummin Posted June 2, 2012 Share Posted June 2, 2012 You could probably get the sum from the query itself SUM(field_name) or use another variable to add up these sub totals. {//your loop $total += $charge; } Link to comment https://forums.phpfreaks.com/topic/263522-add-session-variable-from-repeat-fields/#findComment-1350601 Share on other sites More sharing options...
billhobbs Posted June 2, 2012 Author Share Posted June 2, 2012 that didn't work. any other suggestions? Link to comment https://forums.phpfreaks.com/topic/263522-add-session-variable-from-repeat-fields/#findComment-1350617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.