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 9124497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:35:05+00:00 2026-06-17T06:35:05+00:00

Trying to run a second query for items in an array. First I’ve created

  • 0

Trying to run a second query for items in an array.
First I’ve created an array of user information, then for each of the users I need to query for their answers found in the answers table.

The idea is for the array to have data from the first query and then simply add the data from the answers to the related user element. The code below is only listing the first system.

I’ve been so reluctant to post my question here, but my entire day has been consumed by this and I’m getting no where fast. Apologies in advance for my obviously flawed approach.

 Array
(
    [0] => Array
        (
            [fname] => asdf
            [lname] => asdf
            [minitial] => a
            [rank] => MAJ
            [uniq] => !s5$qn

            [sysName] = System 1 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom

            [sysName] = System 2 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom

            [sysName] = System 3 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom


   [1] => Array
        (
            [fname] => asdf
            [lname] => lkjlkj
            [minitial] => i
            [rank] => oiuoi
            [uniq] => @z26dr

            [sysName] = System 1 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom

            [sysName] = System 2 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom

            [sysName] = System 3 Name
            [choice] = The choice for This named system
            [priority] = The priority 
            [termcom] = The termcom


        )

//CODE

$sql = "SELECT fname, lname, minitial, rank, uniq FROM `user` join answers on answers.uniqid = user.uniq";
$data = mysqli_query($con, $sql) or die("MySQL ERROR: ". mysqli_error($con));

$users = array();
$i = 0;

while ($row = mysqli_fetch_array($data, MYSQL_ASSOC))
{
    $users['answers'][$i] = array (
        "fname" => $row['fname'], 
        "lname" => $row['lname'], 
        "minitial" => $row['minitial'], 
        "rank" => $row['rank'], 
        "uniq" => $row['uniq']
     );

    $query2 = "SELECT a.sysid, s.sysName, uniqid, choice, priority, termcom FROM answers a LEFT JOIN systems s ON s.sysID = a.sysid WHERE a.uniqid = '" . $row['uniq'] . "'";
    $data2 = mysqli_query($con, $query2);

    while ($row2 = mysqli_fetch_array($data2, MYSQL_NUM))
    {       
        $users['answers'][$i]['sysName'] = $row2[1];
        $users['answers'][$i]['choice'] = $row2[3];     
    }

    $i++;
}

Thank you in advance for any insight you might share.

EDIT: This is the array coming back, and only the first system is being listed for each user.

[2] => Array
        (
            [fname] => asdf
            [lname] => lkjlkj
            [minitial] => i
            [rank] => oiuoi
            [uniq] => @z26dr
            [sysName] => Super Terminate System
        )

    [3] => Array
        (
            [fname] => Juuu
            [lname] => kjuuu
            [minitial] => k
            [rank] => LTC
            [uniq] => gthdz%
            [sysName] => Super Terminate System
        )
  • 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-06-17T06:35:06+00:00Added an answer on June 17, 2026 at 6:35 am

    O.K. you don’t exactly tell what happens when you run your script (What is the Problem). But when i look at your coude i can assume what is going wrong.

    First of all, I think you could also do it with on query:

    $sql = "SELECT * FROM `user` 
            join answers on answers.uniqid = user.uniq
            LEFT JOIN systems s ON s.sysID = a.sysid";
    

    Hopefully this helps. Otherwise:

    In your second query there is a problem. I think you should change:

    $query2 = "SELECT a.sysid, s.sysName, uniqid, choice, priority, termcom FROM answers a LEFT JOIN systems s ON s.sysID = a.sysid WHERE a.uniqid = '" . $row['uniq'] . "'";
    

    to

    $query2 = "SELECT a.sysid, s.sysName, s.uniqid, s.choice, s.priority, s.termcom FROM answers a LEFT JOIN systems s ON s.sysID = a.sysid WHERE a.uniqid = '" . $row['uniq'] . "'";
    

    The s. before choice = s.choice

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query I need to run and I have 2 problems. first
I'm using EntityFramework 4.3.1 and trying to run a query like this Context.Set<KullaniciYetkiView>().Where(y =>
I need to use a query to get the last second of an hour
i'm sending session values from my first.php and trying to get from my second.php.
I'm trying to write a query that will: Run a query, give me (x)
I'm trying to take a list of 40,000 items and run a json request
I'm trying to run the following query: insert into visits set source = 'http://google.com'
So what I'm trying to do is: Run this query: SELECT FW_ArtSrcLink FROM FW_ArtSrc
I am trying to query Active directory for a user to get a list
I'm trying to query the data of the second table within my database. I

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.