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
https://forums.phpfreaks.com/topic/267228-adding-up-values-in-a-db-column/
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 ?

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.