I have an array which have this structure:
$queues[n] Array (
[id] => integer
[idClient] => integer
[name] => string
[people] => integer )
Which is populated with:
$query = "SELECT clients.idClient AS 'idClient', queues.idQueue AS 'idQueue', queues.name AS 'name' FROM clients, queues WHERE clients.idClient = queues.client";
$queues = null;
$result = mysql_query($query);
if ($result){
while ($queue = mysql_fetch_assoc($result)){
$queues[] = array ("idClient" => $queue['idClient'], "id" => $queue['idQueue'], "name" => $queue['name'], "people" => 0);
}
}
Each 'n' value match a queue from Database and people, by default is set to 0.
After populating the array I query the database again with each queue to other table to obtain the number of people in queue with a query like this:
SELECT COUNT(*) FROM peoplequeued WHERE queue ='".$queue['name']."'
And then:
$result = mysql_query($query);
if ($result){
$num_people = mysql_fetch_row($result);
$queue['people'] = $num_people[0];
}
And something strange happens here. If I echo the $queue['people'] in the foreach, it shows fine the value it got but if I preview the full array before returning it, it's back to 0.
What could be happening?
$queuevariable?foreachstatements may be the actual cause, but we are unable to determine that because we can't see them. You admitted you had a mistake in your code, but didn't let us figure out where this error is.