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 ......我怎么能这样做?是否有可能像我尝试那样做?
答案 0 :(得分:3)
OR条件需要正确的括号
WHERE user_id=:user_id AND ( vrsta=:trebanam OR vrsta=:trebanam1 )