How would I pull multiple rows from the db and make them into one array...

Discussion in 'PHP' started by x0x, Jan 10, 2010.

  1. #1
    Let's say I have the following rows in my db:

    id	name 	extra	
    1	New York	1.123
    2	Chicago	1.645
    3	Miami	2
    4	Los Angeles	1.999
    5	Las Vegas	1.462
    6	Detroit	1.823
    7	Toronto	1.1
    PHP:
    What I want to do is pull them all (only the name filed) and get them in one array, so it would looks like this:

    "New York", "Chicago", "Miami", etc

    How would I do that?
     
    x0x, Jan 10, 2010 IP
  2. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #2
    Give this a try..

    $resultArray = array();
    
    $result = mysql_query("SELECT name FROM database");
    while ($row = mysql_fetch_row($result))
    {
    $resultArray[] = $row[0];
    }
    PHP:
     
    Silver89, Jan 10, 2010 IP
  3. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use array bush
    or try to use any php mysql class it will make your work very easy with mysql
     
    astkboy2008, Jan 11, 2010 IP