I have a MySQL table:
-------------------
|type_id|type_name|
-------------------
| 22 | Toyota |
| 22 | Mazda |
| 23 | Volvo |
| 23 | Man |
| 25 | Scania |
| 25 | Iveco |
| 25 | Fiat |
-------------------
which is created dynamically from user input. I want to create an array from the table using PHP like this:
array(
'22' => array('Toyota', 'Mazda'),
'23' => array('Volvo', 'Man'),
'25' => array('Scania', 'Iveco','Fiat'),
);
where array id will be type_id and elements will be type_name's of the type_id.I tried this:
$results = array();
while($line = mysqli_fetch_array($result, MYSQL_ASSOC))
{
$results[] = $line;
}
print_r($results);
But I am getting:
Array (
[0] => Array (
[type_id] => 22
[type_name] => Toyota
)
[1] => Array (
[type_name] => 22
[type_name] => Mazda
)
...so on
Please help!