Attn: web gurus...... PHP & SQL question

I have this query:

SELECT money FROM table WHERE x=1.

I need a command that will add ALL the “money” together into one sum… So if this query returns 2 rows w/ money=10 and money=20, I need it to add money and money together, producing money=30… so that when I put the variable $totalmoney it will return the TOTAL of all the rows returned.

Make sense?? :frowning: :frowning:

And yes, this is WORK-RELATED… :squint:

if this is a standard SQL query then just dump all the ‘money’ variables to a file and run a sum of on the file… you’ll have two commands running, but just run the sum command on the query of select money from table… but it doens’t look like you are using common SQL coding, unless that’s a fragment…

too bad i’m not a programmer… but i would just dump that query to a file and simply run a sum command.

if you aren’t a programmer, why are they making you do this? probably when i’m made to run query’s and fix lines of code… :rolleyes:

select Sum(money) from table
where x = 1

Well, this is a query within a PHP file. If I gave the actual query it would look even stranger because it’s using XMB Forum source code, although it’s not a forum. The sum of the total needs to be a variable because it’s going to be printed within HTML in the same file.

too bad i’m not a programmer… but i would just dump that query to a file and simply run a sum command.

? I have a giant PHP book in front of me, and the index says nothing under “sum”. Do you know the command?

if you aren’t a programmer, why are they making you do this? probably when i’m made to run query’s and fix lines of code… :rolleyes:

My “project” is just a database that prints out how many of each instrument and how much total $$ we quoted per instrument between dates x and y… it was 10X easier for me to do it in PHP rather than say Microsoft Access… I have it completely done, except for this last part. I wasn’t told to do it in PHP, just to do it.

Seriously??? It’s as simple as that?

So

$tmoney = mysql_query(“SELECT sum(money) FROM quotes WHERE date>‘$start’ AND date<‘$end’”);
$totalmoney = mysql_result($tmoney);

should work???

if you want a total for each type of instrument for a given date (x)
you do this and it will give you a total for each

select instrument, Sum(money) from table
where x = 1
group by instrument

this will give you something like this with the $ amounts being totals
piano $5000
trumpet $10000
flute $2000
etc…

:itr41: :blue: :itr41: :blue: It works!!!

You don’t realize how long it took me to get some help on that! Of course, 30 minutes after I ask for help here, I actually get it… :hs:

Now tell them you want a rasie and everytime the form is used Showtime gets .50 cent commision non taxable… :smiley:

:rofl: I suppose now that my form will be finally finished I may get a raise… after all this project WAS done months ago until “boss man” decided to change it all around a week ago and make it 10X harder that it originally was… :finger2:

Adaptation = extra 2/dollar on top of what ever regular raise. :smiley:

glad to help…i program sql everyday so its no big deal

hehe, you might wish you hadn’t told me that… :hs:

j/k, it’s not often I can’t figure something out :slight_smile:

see… i thought there was a sum command for that query.

problem solved :cool:

PHP book isn’t much help w/ SQL queries… and I’ve never seen a sum command before… I don’t study PHP & mysql, I just know what I’ve taught myself from coding XMB forums. :slight_smile:

here is a place to look to solve complicated stuff…it has all the analytical functions
good stuff here…
http://www.akadia.com/services/ora_analytic_functions.html

bookmarked. :slight_smile: thanks again… now I’m off to finish my project! :cool:

Looks like Showtime took care of ya.

In SQL as long as you use the “group by” clause to make sets of tuples you have lots of aggregates you can use (sum, avg, max, etc.). Showtime did it right, notice that he has “instruments” as well as the obvoius “money” in the “select” clause, that is because you have to select the attribute you’re grouping by.

-TJ

Qbasic > *

LOL

LET thisthread = die
WHILE
this board is up
IF
whitey does his job
ENDIF