pwes24 Posted February 5, 2008 Share Posted February 5, 2008 Hello everyone. Thank you for being very helpful. I'm creating a shopping cart and I need to add the figures in the 'totals' column. I know I need to use array_sum but I don't know how to lay down the code. Can someone offer some help? Thank you! Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/ Share on other sites More sharing options...
schilly Posted February 5, 2008 Share Posted February 5, 2008 Looks pretty straight forward if you have all your item/qty/price arrays ready: http://ca3.php.net/array_sum Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/#findComment-459215 Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 You're going to need javascript if you want to show the total real time (while they are entering the numbers) Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/#findComment-459240 Share on other sites More sharing options...
pwes24 Posted February 5, 2008 Author Share Posted February 5, 2008 How do I write the values of $row['total_price'] as an array so I can apply array_sum? This is the difficult part Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/#findComment-459261 Share on other sites More sharing options...
Barand Posted February 6, 2008 Share Posted February 6, 2008 <?php while ($row = mysql_fetch_assoc($result)) { $array[] = $row['total_price']; } $total = array_sum ($array); ?> OR <?php $result = mysql_query ("SELECT SUM(total_price) FROM cart"); $total = mysql_result ($result, 0); ?> Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/#findComment-459290 Share on other sites More sharing options...
pwes24 Posted February 6, 2008 Author Share Posted February 6, 2008 Thank you sooo much Barand! I got it! Link to comment https://forums.phpfreaks.com/topic/89621-solved-array_sum-in-table-column/#findComment-459307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.