Mysql Query for multiple args

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bilibytes
    New Member
    • Jun 2008
    • 128

    #1

    Mysql Query for multiple args

    hi all!

    i have a simple array compound of user_id's. (i get this array from a query users table).
    then i want to get from another table, some users info. let's say it is the age of each one.

    how would i do to it?

    should i make a query for each user_id that i have? or is there a smarter way, which does it in a single query?

    i think :

    Code:
    for($i++){
    query(SELECT age FROM other_table WHERE user_id = '$user_id[$i]');
    }
    would be very overhead

    if you just have the name of the thing that does this, or a link to where i can find it, i would be very pleased

    thank you very much
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You could use the IN *function*.

    For example:
    [code=mysql]
    SELECT age FROM myTable WHERE user_id IN(1, 2, 3);
    [/code]
    To generate the list of ID's from an PHP array of ID's, try the implode function.

    Comment

    Working...