View Full Version : Array Help

11-16-2006, 12:11 PM

Just need an help on arrays.

MySQL Table structure.

ID name value
1 c01 abc
2 c01 def
3 c02 xyz

Here i want to structure the data in such a way that name column should be index of array and values should be mapped to index for eg.
[1] => Array ( [c01] => array([0] => abc [1] => def
[2] => Array ( [c02] => array([0] => xyz

Thanks in advance.

SeeIT Solutions
11-16-2006, 12:40 PM
Use this code.. obviously you will have to connect to the database first and fix the query to have the right table name, but this will do what you want.

$result = mysql_query("SELECT * FROM `table`");
while ($row = mysql_fetch_assoc($result)) {
$array[$row['name']][] = $row['value'];

11-16-2006, 04:27 PM
hey thanks buddy.
It worked out.