Putting mysql results into an array?

Discussion in 'PHP' started by jsamdirect, Nov 5, 2007.

  1. #1
    How can I put the results of a mysql select query into an array, for example all the id fields that are not active? This array will then be used in another select query to "not" get any rows with the id's from the first query. The second query will only get the first matching result.

    example of query 1:
    mysql_query("SELECT id FROM users WHERE active='No'");

    example of query 2:
    mysql_query("SELECT * FROM data WHERE id!='".$MyArray."' LIMIT 1");

    So, where I am lost is on how to code the array and if the mysql query will work correctly using an array.
     
    jsamdirect, Nov 5, 2007 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    This can be done with a sub query:

    SELECT * FROM data WHERE id NOT IN (SELECT id FROM users WHERE active='No') LIMIT 1
    Code (markup):
    or a standard join:

    SELECT data.* FROM data, users WHERE data.id = users.id AND users.active = 'No' LIMIT 1
    Code (markup):
    Brew
     
    Brewster, Nov 5, 2007 IP
  3. jsamdirect

    jsamdirect Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nice! Thank you VERY MUCH!
     
    jsamdirect, Nov 5, 2007 IP