具有多个条件的SELECT

时间:2015-08-18 08:40:29

标签: php mysql select

我在php中有多条件查询

$query = sprintf("SELECT * FROM `booking` WHERE `rid` = ".$rid." AND `check_in_date` = ".$check_in_date." AND `check_out_date` = ".$check_out_date);
打印查询时,我希望它像这样

SELECT * FROM `booking` WHERE `rid` = 1 AND `check_in_date` = '2015-10-10' AND `check_out_date` = '2015-10-11'

1 个答案:

答案 0 :(得分:-1)

在查询中,缺少日期引用(日期应视为字符串(varchar):

$rid = '--';
$check_out_date = $check_in_date = ' 2005-12-12 ';
    $query = "SELECT * FROM `booking` WHERE `rid` = '".$rid."' ";
    $query .= " AND `check_in_date` = '".$check_in_date."' ";
    $query .= " AND `check_out_date` = '".$check_out_date . "';"; 

    echo $query;

SELECT * FROM booking WHERE rid =' - '和check_in_date =' 2005-12-12'和check_out_date =' 2005-12-12'