0

I want to query my database tables for a user and return all information about that user. I have multiple tables, one for basic user information and other associated tables for things like emails, phone numbers, etc. because a user can have more than one of these.

If I query for a user that has multiple phone numbers, the query will join the phone numbers from the other table but it will return all of the user's data multiple times, once for each phone number like this:

Array( [name] => 'Bob Barker', [phone] => 'number-1')
Array( [name] => 'Bob Barker', [phone] => 'number-2')

instead of returning all of the user's data once with the phone numbers stored as an array in the returned data like this:

Array( 
  [name] => 'Bob Barker', 
  [phone] => Array(
     [0] => 'number-1',
     [1] => 'number-2',
  )
)

Is it possible to make the query do this?

EDIT: My apologies for not having any table data, I'm asking because my database admin is out of office for a while and I'm trying to figure this out for him but I don't have access to our database.

3
  • 2
    check group_concat. Also a table structure, sample data would help. Commented Aug 29, 2013 at 14:22
  • 3
    @AndaIancu - better to use array-forming in PHP itself (since with group_concat() you still need to explode() data string into desired array) Commented Aug 29, 2013 at 14:23
  • true - depends how you display the data or what you want to achieve with the result set, dao objects etc. Commented Aug 29, 2013 at 14:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.