I have: 14,10,13,12,11,9 in an array called loosephotos (which I can explode into a string if needed...)

I want to query mySQL such that I ask the database, return all rows where ID is 14 or 10 or 13 or 12 or 11 or 9. I guess another way to say it would be, return all rows where any ID equals any array value....

Is there an easy way to do this without looping? Something like:

resultgrab = mysql_query("select * from $itemstable WHERE ID = '$loosephotos' && xrestricted >= $accesslevel ORDER BY '$sortby' $desc limit $limit");

I can explode or do whatever i need to do format it first, and if i HAVE to loop it i will, i just really want to figure this out...

Thanks

    Make it a comma separated string, not an array, so the query ends up looking like this (assuming the ID column is character):

    select * from $itemstable
    WHERE ID in ('14','10','13','12','11','9')
    AND xrestricted >= $accesslevel
    ORDER BY '$sortby' $desc limit $limit

      $inString = implode("','" , $loosePhotos);

      $loosePhotos = "('" . addslashes($loosePhotos) . "')"; // in case the values might be string vs. numeric

      Then your query would just be:

      select ... where ID IN $loosePhotos

        Write a Reply...