MySQL Forums
Forum List  »  PHP

Re: PHP filesize and storing a big WHERE clause in a variable
Posted by: Rick James
Date: October 24, 2010 10:01PM

Gag... What if there are 107 home teams tomorrow?
WHERE hometeam IN('$_POST[option1]' ,'$_POST[option2]' ,'$_POST[option3]' ,'$_POST[option4]' ,'$_POST[option5]' ,'$_POST[option6]' ,'$_POST[option7]' ,'$_POST[option8]' ,'$_POST[option9]' ,'$_POST[option10]' ,'$_POST[option11]' ,'$_POST[option12]' ,'$_POST[option13]' ...
AND awayteam IN ...
-->
function BuildInList($a, $z)
{
    $ins = array();
    foreach (range($a, $z) as $n)   // flexibility
    {
        $val = @$_POST["option$n"];    // @ avoids a noisy warning
        if (isset($val))               // missing arg?
        {
            $eval = mysql_real_escape_string($val);  // bulletproofing
            $ins[] = "'$eval'";
        }
    }
    return implode(', ', $ins);   // build commalist
}
...
$ht_ins = BuildInList(1, 106);    // A lot less typing
$at_ins = BuildInList(132, 262);
...WHERE hometeam IN ($ht_ins)
     AND awayteam IN ($at_ins) ...

Options: ReplyQuote


Subject
Written By
Posted
Re: PHP filesize and storing a big WHERE clause in a variable
October 24, 2010 10:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.