[thelist] MySQL "OR"

Andrew Kamm akamm at demicooper.com
Thu Sep 8 07:50:48 CDT 2005

Is it proper to execute a rather long SQL query in MySQL?  I'm not aware of
a reason this wouldn't work (unless there is simply a limit on the length of
a queries), but I'm not sure if it's bad form or if the DB would respond

Please see the PHP code below.  At this point in the code, I've gathered an
array of advertiser_id's from a separate function, and I want to do a query
that basically says "SELECT X FROM TABLE Y WHERE advertiser_id = $q_or"
where $q_or is the imploded array below.  As the app grows, this could
become a potentially long list of "OR's".

if (is_array($advertisers))
        {    //Wrap array values with ' '
            foreach($advertisers as $value)
                $newAdvertisers[] = "'".$value."'";
            //Create 'or' section of query with array
            $q_or = implode(" OR advertiser_id = ", $newAdvertisers);

            //SELECT STATEMENT, ETC....

Thanks in advance!

Andrew Kamm

More information about the thelist mailing list