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

  • SEARCH
  • Home
  • 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 6829645
In Process

The Archive Base Latest Questions

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

I have a mysql DB with those column id , idUser , idCompany ,

  • 0

I have a mysql DB with those column id , idUser , idCompany , idProfession for users table.

Now i would Select all those field and make an array that is build in this way :
array[idUser] = array [id=> x , idCompany => xx , idProfession => xxx)

For example 1 user could work for more company and do different profession.
So each array[idUser] Could have multiple array(id, idCompany,idProfession) and i would have 1 result for each idUser instead multiple result for the same idUser.

Now after i did the query i wrote this code but of course id doesnt do what i want becouse it replace always the same element with another one cause the while loop.

$data=array();
$sql_result="SELECT etc...........";

    while($rows = mysql_fetch_array($sql_result,MYSQL_BOTH)){
        $data[idUser] = array('idCompany' => $rows['idCompany'], 'profession' => $rows['idProfession'] ); 

I was thinking to do a for loop in the while , store the data in a tmp array.

But i had to stop becouse i didnt understand how to do that.

  • 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-26T22:31:29+00:00Added an answer on May 26, 2026 at 10:31 pm

    Does this do what you want?

    $users=array();
    $sql_result="SELECT * FROM users";
    
    while($row = mysql_fetch_array($sql_result,MYSQL_BOTH)){
        $users[ $row['idUser'] ][] = array('idCompany' => $row['idCompany'], 'profession' => $row['idProfession'] ); 
    }
    

    This will populate the array like this:

    array(
      idUser => array(
          array('idCompany', 'profession'),
          array('idCompany', 'profession'),
          etc..
         )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql table that has a column that stores xml as a string.
I'm make a little game in php with mysql. Now I have a problem
In my MySQL DB table I have a column called StartDate (of varchar type)
I have counter for unique column in my table. Now I have list where
Scenario : I have say 4 check boxes and users can select those checkboxes
I have a MySQL table to hold tags (i.e. like those used here on
Suppose I have a column of heights -- how can I select all and
I have a MySQL table on which I'm executing SELECT statements within Python. Is
I have a MySQL query that looks like this: UPDATE `Table` SET `Column` =
I have a table in a MySQL database with an ID column. This is

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.