Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MYSQL在预订持续到下个月时返回结果_Php_Mysql_Sql_Wordpress_Union - Fatal编程技术网

PHP MYSQL在预订持续到下个月时返回结果

PHP MYSQL在预订持续到下个月时返回结果,php,mysql,sql,wordpress,union,Php,Mysql,Sql,Wordpress,Union,我正在wordpress中编辑一个预订系统的code nation hotel主题,试图解决这样一个问题:当用户在入住日期后的一个月内选择退房日期时,返回0个结果 以下是预订页面的原始代码: $dayFirst = date("d",strtotime($_POST["check-in"])); $monthFirst = date("m",strtotime($_POST["check-in"])); $yearFirst = date("Y",strtotime($_POST["check-

我正在wordpress中编辑一个预订系统的code nation hotel主题,试图解决这样一个问题:当用户在入住日期后的一个月内选择退房日期时,返回0个结果

以下是预订页面的原始代码:

$dayFirst = date("d",strtotime($_POST["check-in"]));
$monthFirst = date("m",strtotime($_POST["check-in"]));
$yearFirst = date("Y",strtotime($_POST["check-in"]));
$dayLast = date("d",strtotime($_POST["check-out"]));
$monthLast = date("m",strtotime($_POST["check-out"]));
$yearLast = date("Y",strtotime($_POST["check-out"]));

$price = $wpdb->get_row( $wpdb->prepare( 
    "SELECT min_price FROM {$wpdb->prefix}nation_booking_calendars WHERE id='%d'",
    $calID
    ) );
$minPrice = $price->min_price;
                                               $roomAvailty = $wpdb->get_results( $wpdb->prepare( 
    "SELECT * FROM {$wpdb->prefix}nation_booking_availability 
    WHERE calendar_id='%d' 
        AND day >= $dayFirst 
        AND month >= $monthFirst 
        AND year >= $yearFirst 
        AND day < $dayLast 
        AND month <= $monthLast 
        AND year <= $yearLast 
        AND availability >= %d ",
    $calID,$_POST["room-number"]
    ) );

if ( count($roomAvailty) == count( $dateRange ) ) {
    $roomAvailable = true;
}

为什么你们要把日、月、年分开列?嗨,草莓,恐怕不知道。对我来说似乎很傻,但我正在编辑其他人的代码/数据库结构。不确定实际的修复方法,但我的解决方案是删除语句的联合部分,单独运行sql查询,然后将结果数组与php合并。这很好。所以,现在是你解决这个问题的机会。
if($monthFirst==$monthLast) {                       
    $roomAvailty = $wpdb->get_results( $wpdb->prepare( 
        "SELECT * 
        FROM {$wpdb->prefix}nation_booking_availability 
        WHERE calendar_id='%d' 
            AND day >= $dayFirst 
            AND month >= $monthFirst 
            AND year >= $yearFirst 
            AND day < $dayLast 
            AND month <= $monthLast 
            AND year <= $yearLast 
            AND availability >= %d ",
        $calID,$_POST["room-number"]
        ) );
}
else {
    $roomAvailty = $wpdb->get_results( $wpdb->prepare( 
        "(SELECT * FROM {$wpdb->prefix}nation_booking_availability 
            WHERE calendar_id='%d' 
                AND day >= $dayFirst 
                AND day <= $maxdays 
                AND month = $monthFirst 
                AND year = $yearFirst 
                AND availability >= %d)
        UNION ALL
            (SELECT * FROM {$wpdb->prefix}nation_booking_availability 
            WHERE calendar_id='%d' 
                AND day >= $mindays 
                AND day < $dayLast 
                AND month = $monthLast
                AND year = $yearLast 
                AND availability >= %d)
        UNION ALL
            (SELECT * FROM {$wpdb->prefix}nation_booking_availability 
                WHERE calendar_id='%d' 
                    AND month > $monthFirst 
                    AND month < $monthLast 
                    AND year = $yearFirst 
                    AND availability >= %d) ",
        $calID,$_POST["room-number"]
        ) );
}
id  calendar_id day month year availability price
101 11          2   9     2014 1            95
102 11          3   9     2014 1            95
103 11          4   9     2014 1            95
104 11          5   9     2014 1            95
105 11          6   9     2014 1            95
106 11          7   9     2014 1            95
107 11          8   9     2014 1            95
108 11          9   9     2014 1            95
109 11         10   9     2014 1            95