#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2

    Problem Querying Multiple Rows


    All I'm trying to do is create an array with all the id's that have a value of 0 in the status column of the table.

    PHP Code:
    $query mysql_query("SELECT `tempID` FROM `pending` WHERE `status` = 0");
    $status mysql_fetch_array($query); 
    This codes has only been returning a single row any ideas?
  2. #2
  3. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    The docs have the answer:
    mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both
    To retrieve all values in the column you have to loop through them. Example (again from the docs):
    PHP Code:
    <?php
    mysql_connect
    ("localhost""mysql_user""mysql_password") or
        die(
    "Could not connect: " mysql_error());
    mysql_select_db("mydb");

    $result mysql_query("SELECT id, name FROM mytable");

    while (
    $row mysql_fetch_array($resultMYSQL_NUM)) {
        
    printf("ID: %s  Name: %s"$row[0], $row[1]);  
    }

    mysql_free_result($result);
    ?>
    You will need to modify this (or similar examples) to store the column values in a PHP array.

    NB The mysql extension is deprecated and "will be removed in the future".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2
    Originally Posted by AndrewSW
    The docs have the answer:

    To retrieve all values in the column you have to loop through them. Example (again from the docs):

    You will need to modify this (or similar examples) to store the column values in a PHP array.
    Awesome, thanks for the help works perfectly.

    PHP Code:
    while ($row mysql_fetch_array($queryMYSQL_NUM)) {
         
    $status[$i] =  $row[0];
         
    $i++;


IMN logo majestic logo threadwatch logo seochat tools logo