[thelist] sql group one field

Damien COLA damiencola at wanadoo.fr
Wed Sep 1 04:18:10 CDT 2004


of course..... I forgot soemthign obvious..

php code in email (not verified) :

$results = mysql_query("SELECT serie, model FROM `tablename` ORDER BY
model"); 
$output = array(); 
$mykey = '';
while($row = mysql_fetch_assoc($results)) {
// if $mykey is different than the row's model
// then update $mykey for next loop
// and create a new key in the main array ($output)
   if ($row[model] != $mykey) {
	$output[$row[model]] = array();
	$mykey = $row[model];
   }

// add the serie value to the current model's array
   array_push($output[$row[model]], $row[serie]);	
}

-----Original Message-----
I'm sure there is a one-shot way of doing this, but here would be my
attempt (PHP example to show algorithm -- without error checking):



More information about the thelist mailing list