StarvingArtist Posted December 2, 2009 Share Posted December 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183767-sum-query-is-right-but-cannot-get-at-the-field-it-is-grouped-by-in-the-php-code/ Share on other sites More sharing options...
kickstart Posted December 2, 2009 Share Posted December 2, 2009 Hi Looks like you have a comma missing:- $osql = "SELECT SUM(`sold`), `artist` FROM buttons GROUP BY `artist` LIMIT 2 "; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/183767-sum-query-is-right-but-cannot-get-at-the-field-it-is-grouped-by-in-the-php-code/#findComment-970129 Share on other sites More sharing options...
StarvingArtist Posted December 3, 2009 Author Share Posted December 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183767-sum-query-is-right-but-cannot-get-at-the-field-it-is-grouped-by-in-the-php-code/#findComment-970318 Share on other sites More sharing options...
kickstart Posted December 3, 2009 Share Posted December 3, 2009 Hi After too many years I like SQL, and find MySQL to be one of the nicest implementations to use. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/183767-sum-query-is-right-but-cannot-get-at-the-field-it-is-grouped-by-in-the-php-code/#findComment-970329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.