AND - 或php pdo中的运算符

时间:2014-07-01 15:28:38

标签: php mysql pdo

php中是否有OR运算符?

我写这段代码但是不行,因为我使用OR运算符:

$trebanam = 'seme';
$trebanam1 = 'sadnice';


    # basic pdo connection (with added option for error handling)
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { 
     $statement=$db->prepare("SELECT id,vrsta,artikl,bruto_kol FROM zalihe WHERE user_id=:user_id AND vrsta=:trebanam OR vrsta=:trebanam1");
$statement->execute(array(':user_id' => $user_id, ':trebanam'=>$trebanam, ':trebanam'=>$trebanam1));
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
echo $json;
     }
    else { 
echo 'GRESKA 404';
    }
    ?>

所以在这里我需要获取数据,其中vrsta = seme或vrsta = sadnice ......我怎么能这样做?是否有可能像我尝试那样做?

1 个答案:

答案 0 :(得分:3)

OR条件需要正确的括号

WHERE user_id=:user_id AND ( vrsta=:trebanam OR vrsta=:trebanam1 )