php中查詢最近一個月的查詢代碼報錯,請教咋辦

來源:互聯網
上載者:User
php中查詢最近一個月的查詢代碼報錯,請問咋辦
//最近一月的訂單
$sql_month="select order_id , order_number from order_table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(order_date)" ;
var_dump($sql_month) ;
$mysql_month=mysql_query($sql_month) or die("Could not query.".mysql_error()) ;
$info_month=mysql_num_rows($mysql_month) ;
if($info_month==""){
$html_info_month="最近一月沒有訂單。" ;
}
else{
$str=mysql_fetch_array($mysql_month) ;
// $html_info_month="最近一月的訂單" ;
$html_info_month="
    " ;
    do{
    $order_id=iconv("gb2312" , "utf-8//IGNORE" , $str["order_id"]) ;
    $order_number=iconv("gb2312" , "utf-8//IGNORE" , $str["order_number"]) ;
    $html_info_month.="
  • ".$order_number."
  • " ;
    }while($str=mysql_fetch_array($mysql_month)) ;
    $html_info_month.="
" ;
}
查詢最近一個月的select語句,是正確的嗎?
報錯:
string(120) "select order_id , order_number from order_table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(order_date)" Could not query.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') <= date(order_date)' at line 1
------解決方案--------------------
select order_id , order_number from order_table where date > ".strtotime('-1 month')
------解決方案--------------------
1 其實你只想問那句sql,那就不要貼代碼了,太多了,好多人不喜歡看
2 $sql_month="select order_id , order_number from order_table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(order_date)" 意思是找出那些訂單的日期加上一個月都還要小於等於當前日期的,而最近一個月的意思是訂單日期比當前日期小一個月之內的資料,也就是訂單日期加上一個月大於等於當前日期的,所以應該是select order_id , order_number from order_table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) >= date(order_date)"
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.