Sql显示每个查询而不是特定的

时间:2017-08-08 21:11:14

标签: php mysql

问题是:

$type =我的r_areal变量

$sqlc = "SELECT * FROM reservation where r_areal IN ('".$type."') and '".$cid."' between r_start and r_ende 
            or where r_areal IN ('".$type."') '".$cod."' between r_start and r_ende 
            or where r_areal IN ('".$type."') '".$cid."'<= r_start AND '".$cod."' >= r_ende


            ";

所以这是我对sql的php查询。它可以工作,但它显示了我的数据库中每个$type的每个sql行。但它应该只显示f.e的所有行。参数B.我知道,一个问题是where r_areal IN ('".$type."')只被接受一次。但是,如果我删除第二个和第三个,它会显示所有$type的所有行。

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

使用括号分隔AND和OR条件。

$sqlc = "SELECT * FROM reservation 
    WHERE (r_areal IN ('".$type."') AND '".$cid."' BETWEEN r_start AND r_ende) 
            OR  (r_areal IN ('".$type."') '".$cod."' BETWEEN r_start AND r_ende)
            OR (r_areal IN ('".$type."') '".$cid."'<= r_start AND '".$cod."' >= r_ende)
            ";