cdoggg94 Posted August 21, 2012 Share Posted August 21, 2012 <?php $link = mysql_connect('localhost', 'user', 'pw'); if (!$link) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db('my_DB')) { die('Could not select database: ' . mysql_error()); } $query = mysql_query("SELECT SUM(wish_total) FROM wish_list WHERE wish_product= '30108'"); if (!$query) { die('Could not query:' . mysql_error()); } echo mysql_result($query); ?> in the code above i am trying to add up the wish_total column in my table wish_list. When i ran this query in phpmyadmin, it added it up fine. Im not sure if i am echoing the correct thing, because i think that the query is working. suggestions ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 21, 2012 Share Posted August 21, 2012 Do you get an error from mysql error? What output do you get? You will want to assign that SUM a name btw. SELECT SUM(wish_total) AS summed_wish_total FROM wish_list WHERE wish_product= '30108' Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 I don't normally use mysql_result, but I think the row parameter is not optional: echo mysql_result($query,0); Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted August 21, 2012 Author Share Posted August 21, 2012 I do not get an error... Basically it it left blank. I will try the to assign it as you have stated and get back to you. Sorry i was away for an hour. I will respond very soon! Quote Link to comment Share on other sites More sharing options...
cdoggg94 Posted August 21, 2012 Author Share Posted August 21, 2012 I think with the additions you 2 have made to my script it is working the way it should be ! Many thanks ! I appreciate it very much ! 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.