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

**URL:** <https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732>\
**Category:** PittSpeed Off Topic\
**Created:** [May 25, 2004, 9:56am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732 "2004-05-25T09:56:14Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 9:56am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/1 "2004-05-25T09:56:14Z")

</div>

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?? ☹ ☹

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

---

<div class="post-metadata">

**Author:** ![fshowcars](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/fshowcars/32/5937_2.png) [@fshowcars](https://forums.speedlife.net/u/fshowcars)\
**Post date:** [May 25, 2004, 10:10am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/2 "2004-05-25T10:10:43Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![imported\_showtime](https://avatars.discourse-cdn.com/v4/letter/i/51bf81/32.png) [@imported\_showtime](https://forums.speedlife.net/u/imported_showtime)\
**Post date:** [May 25, 2004, 10:16am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/3 "2004-05-25T10:16:36Z")

</div>

select Sum(money) from table  
where x = 1

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:17am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/4 "2004-05-25T10:17:27Z")

</div>

> [@turbovw18](#):
>
> 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…

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.

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:19am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/5 "2004-05-25T10:19:24Z")

</div>

> [@showtime](#):
>
> select Sum(money) from table  
> where x = 1

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???

---

<div class="post-metadata">

**Author:** ![imported\_showtime](https://avatars.discourse-cdn.com/v4/letter/i/51bf81/32.png) [@imported\_showtime](https://forums.speedlife.net/u/imported_showtime)\
**Post date:** [May 25, 2004, 10:23am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/6 "2004-05-25T10:23:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:25am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/7 "2004-05-25T10:25:25Z")

</div>

: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:

---

<div class="post-metadata">

**Author:** ![Sight\_N\_Sound](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/sight_n_sound/32/5950_2.png) [@Sight\_N\_Sound](https://forums.speedlife.net/u/Sight_N_Sound)\
**Post date:** [May 25, 2004, 10:33am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/8 "2004-05-25T10:33:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:37am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/9 "2004-05-25T10:37:21Z")

</div>

> [@Sight N Sound](#):
>
> Now tell them you want a rasie and everytime the form is used Showtime gets .50 cent commision non taxable… 😃

🤣 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:

---

<div class="post-metadata">

**Author:** ![Sight\_N\_Sound](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/sight_n_sound/32/5950_2.png) [@Sight\_N\_Sound](https://forums.speedlife.net/u/Sight_N_Sound)\
**Post date:** [May 25, 2004, 10:40am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/10 "2004-05-25T10:40:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![imported\_showtime](https://avatars.discourse-cdn.com/v4/letter/i/51bf81/32.png) [@imported\_showtime](https://forums.speedlife.net/u/imported_showtime)\
**Post date:** [May 25, 2004, 10:46am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/11 "2004-05-25T10:46:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:52am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/12 "2004-05-25T10:52:23Z")

</div>

> [@showtime](#):
>
> 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 🙂

---

<div class="post-metadata">

**Author:** ![fshowcars](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/fshowcars/32/5937_2.png) [@fshowcars](https://forums.speedlife.net/u/fshowcars)\
**Post date:** [May 25, 2004, 10:52am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/13 "2004-05-25T10:52:23Z")

</div>

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

problem solved 🆒

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:52am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/14 "2004-05-25T10:52:52Z")

</div>

> [@turbovw18](#):
>
> see… i thought there was just a sum command for that query.

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. 🙂

---

<div class="post-metadata">

**Author:** ![imported\_showtime](https://avatars.discourse-cdn.com/v4/letter/i/51bf81/32.png) [@imported\_showtime](https://forums.speedlife.net/u/imported_showtime)\
**Post date:** [May 25, 2004, 10:55am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/15 "2004-05-25T10:55:35Z")

</div>

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](http://www.akadia.com/services/ora_analytic_functions.html)

---

<div class="post-metadata">

**Author:** ![ninjenn](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@ninjenn](https://forums.speedlife.net/u/ninjenn)\
**Post date:** [May 25, 2004, 10:58am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/16 "2004-05-25T10:58:15Z")

</div>

> [@showtime](#):
>
> 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](http://www.akadia.com/services/ora_analytic_functions.html)

bookmarked. 🙂 thanks again… now I’m off to finish my project! 🆒

---

<div class="post-metadata">

**Author:** ![tjZ28](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@tjZ28](https://forums.speedlife.net/u/tjZ28)\
**Post date:** [May 25, 2004, 10:58am UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/17 "2004-05-25T10:58:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![berad](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/berad/32/5953_2.png) [@berad](https://forums.speedlife.net/u/berad)\
**Post date:** [May 25, 2004, 12:00pm UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/18 "2004-05-25T12:00:34Z")

</div>

Qbasic \> \*

---

<div class="post-metadata">

**Author:** ![fshowcars](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/fshowcars/32/5937_2.png) [@fshowcars](https://forums.speedlife.net/u/fshowcars)\
**Post date:** [May 25, 2004, 12:53pm UTC](https://forums.speedlife.net/t/attn-web-gurus-php-sql-question/166732/19 "2004-05-25T12:53:35Z")

</div>

> [@scfb518t](#):
>
> Qbasic \> \*

LOL

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