MYSQL下个月查询无效

时间:2015-09-04 14:39:48

标签: mysql

我希望有人可以帮我解决问题。我试图从mysql数据库中获取所有行,其中'end'属于下一个日历月。目前,我的查询只是在下一个日历月内拉出“开始”的行。

   if (! empty($_GET['skill'])) $whereClauses[] ="skill LIKE('%".mysqli_real_escape_string($db_conx,$_GET['skill'])."%')";
if (!empty($_GET['start']))
    if ($_GET['start'] == "today") {
        $whereClauses[] = "START = CURDATE()";
    }
else if ($_GET['start'] == "tomorrow") {
        $whereClauses[] = "START = DATE_ADD( CURDATE( ) , INTERVAL( 9 - IF( DAYOFWEEK( CURDATE( ) ) =1, 8, DAYOFWEEK( CURDATE( ) ) ) ) DAY )";   
    }
else if ($_GET['start'] == "next_week") {
        $whereClauses[] = "START = DATE_ADD( CURDATE( ) , INTERVAL( 9 - IF( DAYOFWEEK( CURDATE( ) ) =1, 8, DAYOFWEEK( CURDATE( ) ) ) ) 
DAY )";   
    }
else if ($_GET['start'] == "this_month") {
        $whereClauses[] = "START BETWEEN DATE_SUB( CURDATE( ) , INTERVAL( DAY( CURDATE( ) ) -1 ) DAY ) AND LAST_DAY( NOW( ) )";   
    }
    else if ($_GET['start'] == "next_month") {
        $whereClauses[] = "start BETWEEN DATE_SUB(LAST_DAY(DATE_ADD(NOW(), INTERVAL 1 MONTH)),INTERVAL DAY(LAST_DAY(DATE_ADD(NOW(), INTERVAL 1 MONTH)))-1 DAY) AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 1 MONTH))";
    }
else if ($_GET['start'] == "in_future") {
        $whereClauses[] = "START > CURDATE()";   
    }

然后

$sql="SELECT * FROM mytable " .$where."";

我做错了什么?

1 个答案:

答案 0 :(得分:0)

答案是这个

SELECT * FROM mytable WHERE  
FLOOR(start/100)<=FLOOR(NOW()/100000000)+1 AND
FLOOR(  end/100)>=FLOOR(NOW()/100000000)+1

this page

上的Cars10友情提供