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? Quote 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? Quote 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; } Quote 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? Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.