1.
for (...)
{
    if (str != "") str += " or ";
    str += ...
    ....
}2.
for ()
{
    str += ...
}
str = str.substr(0, str.length() - 3);

解决方案 »

  1.   

    $array=array('1','2','3','4');
    $select="select * from table where id>0";$select .= " and (";
    for($i=0; $i<count($array)-1; $i++) {
        $select .= " page=" . $array[$i] . " or ";
    }$select .= " page=" . $array[$i] . ")";
      

  2.   

    $array=array('1','2','3','4');
    $select = 'select * from table where id>0';
    $select .= ' and (';
    for($i=0;$i< sizeof($array);$i++){
    $select .= " page='" . $array[$i] . "'";
    if ($i != sizeof($array)-1) $select .= ' or ';
    }$select=$select.")";
    echo $select;