cdoggg94 Posted August 17, 2012 Share Posted August 17, 2012 So I want to add up all of the entries in my "wish_total" column, that is inside my "wish_list" table. ...I also only want it to add them up if the date and another number is correct... my query goes like this: <?php $totalnum = $_GET['Details']; $totalinfo = mysql_query("SELECT wish_total FROM wish_list WHERE wish_date='".$mymessage."' AND wish_product=".$totalnum." COMPUTE SUM(SIZE)"); ?> I got this example from here: http://stackoverflow.com/questions/2628159/sql-add-up-all-row-values-of-one-column-in-a-singletable I dont really know if it is working or not because i don't know how to display the results. I have just tried to echo $totalinfo, but nothing really came out. Advice would be fantastic! Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/ Share on other sites More sharing options...
trq Posted August 17, 2012 Share Posted August 17, 2012 I'm really not sure where your getting your syntax from. mysql_query("SELECT SUM(wish_total) FROM wish_list WHERE wish_date = '" . $mymessage . "' AND wish_product = " . $totalnum); Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/#findComment-1370175 Share on other sites More sharing options...
cdoggg94 Posted August 17, 2012 Author Share Posted August 17, 2012 Thank you! But where is this content displayed? Or how to i display the calculation.. Like I can't just do this: <?php echo mysql_query("SELECT SUM(wish_total) FROM wish_list WHERE wish_date = '" . $mymessage . "' AND wish_product = " . $totalnum);?> Nothing comes up..So how can it be displayed ? Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/#findComment-1370188 Share on other sites More sharing options...
xyph Posted August 17, 2012 Share Posted August 17, 2012 You can't just echo out a query. You have to parse the results. mysql_result will help you with a single row result, and the manual has examples on how to use. Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/#findComment-1370192 Share on other sites More sharing options...
jardrake Posted August 19, 2012 Share Posted August 19, 2012 With that query you had: <?php echo mysql_query("SELECT SUM(wish_total) FROM wish_list WHERE wish_date = '" . $mymessage . "' AND wish_product = " . $totalnum);?> just rename the sum(wish_total) so that you can get that value like: <?php echo mysql_query("SELECT SUM(wish_total) AS new_total FROM wish_list WHERE wish_date = '" . $mymessage . "' AND wish_product = " . $totalnum);?> Then fetch that new_total with mysql_fetch_array() *please try to stay away from mysql* commands as they are deprecated, please use mysqli instead Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/#findComment-1370719 Share on other sites More sharing options...
fenway Posted August 20, 2012 Share Posted August 20, 2012 I'm really not sure where your getting your syntax from. Transact-SQL. Quote Link to comment https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/#findComment-1370985 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.