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! Quote Link to comment 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 Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment 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! Quote Link to comment 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.