Jump to content

Adding up values in a DB column


cdoggg94

Recommended Posts

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!

 

Link to comment
Share on other sites

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 ?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.