Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:29:54+00:00 2026-05-22T22:29:54+00:00

I have an array which have this structure: $queues[n] Array ( [id] => integer

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:29:55+00:00Added an answer on May 22, 2026 at 10:29 pm

    My guess is that you’re looping through $queues with foreach loop like this:

    foreach ( $queues as $queue ) {
        $result = mysql_query($query);
        if ($result){
            $num_people = mysql_fetch_row($result);
            $queue['people'] = $num_people[0];
        }
    }
    

    If so, there’s no “link” between $queue and $queues[$n], i.e., by modifying $queue, you do NOT modify $queues.

    If this is the case, you should either use $queue as reference variable, or modify $queues[$n] with $n being an index.

    foreach ( $queues as &$queue ) { // add & so $queue is a reference to an element in $queues
        $result = mysql_query($query);
        if ($result){
            $num_people = mysql_fetch_row($result);
            $queue['people'] = $num_people[0];
        }
    }
    unset($queue); // drop the reference, otherwise you might have unexpected results after modifying $queue outside the loop
    

    … or …

    foreach ( $queues as $n => $queue ) { // store index of "current" element in $n
        $result = mysql_query($query);
        if ($result){
            $num_people = mysql_fetch_row($result);
            $queues[$n]['people'] = $num_people[0]; // change $queue to $queues[$n]
        }
    }
    

    Alternatively, I would advise you to think about getting all data in a single statement. It looks like something like this might work for you:

    select
        baseTable.id,
        baseTable.idClient,
        baseTable.name,
        peopleCount.count as people
    from
        baseTable
        left join (
            select
                count(*) as count,
                queue
            from
                peoplequeued
            group by
                queue
        ) as peopleCount on peopleCount.queue = baseTable.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following structure: MyClass { guid ID guid ParentID string Name }
Lets say I have an array with a structure like this: $arr= Array( array(
Ok I have a mult-dimensional array which has the following structure... 0 => array
Hey people i have this structure for the search tree class State { //CLASS
I have the following link structure for my portfolio: <?php echo $this->Html->link($post['Portfolio']['title'], array('controller' =>
I have an array which is a list of domains, I want to print
I have an array in PHP which holds a bunch of unix timestamps. As
I have an array of objects which populate a UITableView . When a user
I have a big lump of binary data in a char[] array which I
I have two questions: 1) How can I make an array which points to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.