Jump to content

SUM query is right, but cannot get at the field it is grouped by in the PHP code


Recommended Posts

MySQL v. 5.0.45  PHP v. 5.2.5

 

Code:

 

$osql = "SELECT SUM(`sold`) `artist` FROM buttons GROUP BY `artist` LIMIT 2 ";

$money = mysql_query($osql);

 

while  (list($dollars) = mysql_fetch_array($money))

{

    echo " Money: $dollars <br />";

}

 

The following results from the echo statement show that the query is correct and functioning properly (there are only two artists):

 

Money: 257.3

Money: 171.9

 

Because the money is right, I know the GROUP BY 'artist' part is right.

 

QUESTION:

For each Money row, how can I print out the name of the artist, which of course was used to SUM the money column??

 

This db is for my use only, and I'm building administrative functions for it and have been stuck on this one for almost 8 hours now.

 

I've searched in vain for this kind of operation with no luck.

 

Thanks much to whomever can solve this!

 

Clair

Hi kickstart -

Thank you!

 

Very much and grrrrr. Once I start a db I am an addict and find that one thing leads to another. I cut my web teeth on perl years ago but discovered PHP about 3 years ago. I think I really like it. MySQL, however, is another kettle of fish entirely. I find it wholly non-intuitive and clumsy.

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.