merging multiple rows in mySQL

Started by Les Mackenzie, February 09, 2005, 01:02:25 PM

Previous topic - Next topic

Les Mackenzie

I have a row readout that I've generated using a while loop that looks something like this:

name                                   1x               2x             3x
someguy                              10              0               0
someguy                               0               10             0
someguy                               0               0               25

As stored in the database but want it to show up on one line:

name                                   1x               2x             3x
someguy                              10              10              25

Is there a way I can do this is PHP?  The GROUP BY in MySQL doesn't accomplish this and I can't figure out how to update the values.  Can someone please help?  Thanks in advance.
BLOGS SUCK! - HERE READ MINE

Please Note:  Arguing on the internet is like running in the Special Olympics...  Even if you win you're still retarded.

[Unknown]

You'd either have to reprocess it, GROUP BY using SUM, or use GROUP_CONCAT... but that's 4.1.x only I think.

http://forums.mysql.com/read.php?87,6929,6929

Of course, you can easily do it with PHP.

if (isset($table[$row['name']]))
{
   $table[$row['name']]['1x'] += $row['1x'];
   $table[$row['name']]['2x'] += $row['2x'];
   $table[$row['name']]['3x'] += $row['3x'];
}
else
   $table[$row['name']] = $row;

-[Unknown]

Les Mackenzie

BLOGS SUCK! - HERE READ MINE

Please Note:  Arguing on the internet is like running in the Special Olympics...  Even if you win you're still retarded.

Advertisement: