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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts

    creating an array from database data

    I am trying to run a mysql_query and return all the results which match the criteria, and then create an array with that data. Any ideas of the best way to do this?

    I was using mysql_fetch_assoc(); but then I realized that this function only returns a single result at a time. Are there any functions that will return all the results into an array? Or another way to solve my problem?

    Thanks!

    Smesh

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    $result mysql_query('SELECT * FROM table') or exit(mysql_error());
    while (
    $row mysql_fetch_assoc($result)) {$array[] = $row;}

    print_r($array); 

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks!

    Works perfectly

    Smesh

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use mysql_fetch_array($result)?


  •  

    Posting Permissions

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