I have a MySQL count, group-by query. It results in a 2 D array. I'm stuck on how to assign the values to a list of variables using the while/foreach loops. I've tried all sorts of crazy things, but cannot get it.
$sql = "SELECT riounit AS unit
, COUNT(riounit) AS countunit
FROM $c_keytable
GROUP BY riounit
ORDER BY riounit" ;
$result = mysql_query ( $sql ) ;
$i = 1 ;
while ( $row = mysql_fetch_assoc ( $result ) )
{
foreach ( $row as $countunit => $value )
{
${unit . $i} = $countunit[$value] ;
$i++ ;
}
}
// desired results:
$unit1 = 3
$unit2 = 5
$unit3 = 2
$unit4 = 7 ... etc.