I want to query my database and get two things, store them in an array and retrieve them later.

Let's say the fields are zone_id and zone_name.

currently i am trying this to store them in array like this

$zone_array = array('zone1index' => zone1name,
'zone2index' => zone2name,
'zone3index' => zone3name);

and retrieve it by something like this

$zone_id = $zone_array[index, 0]; //zero indicating the key of the one I want
$zone_name = $zone_array[value,0];

Is a retrieval like this even possible or am I storing the array incorrectly?

I will be incrementing the key each time I call the array, so I will need to be able to have the '0' variable.


Thanks for your help. Let me know if you need more clarification.

I would suggest the following:

$zone=array('id'=>array(),'name'=>array());
while ($row=mysql_fetch_assoc($result)) {
$zone['id'][]=$row['zone_id'];
$zone['name'][]=$row['zone_name'];
}
//first index
echo $zone['id'][0];
echo $zone['name'][0];
//second index
echo $zone['id'][1];
echo $zone['name'][1];

How be sure that not much data is being stored in the array (>1MB) as you can make your script run out of memory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.