Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question PHP MySQL result into Array

    Hello,

    I would like to "SELECT * FROM 'table'" and put the result into an array, but the array keys should represent the table columns (assuming I don't know them in advance).

    I see many examples for code that extracts the data into arrays in which I have to put the keys manually, but I'm looking for something automatic.

    For example, if the table is something like this:
    ID Name Address
    -- ----- --------
    1 John New York
    2 Terry Miami

    The array should be:
    [ID]=>1 [Name]=>John [Address]=> New York
    [ID]=>2 [Name]=>Terry [Address]=> Miami

    What should I do?

    Thanks,

    David

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Check out mysql_fetch_assoc().

  • Users who have thanked Inigoesdr for this post:

    dstu (05-19-2011)

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •