Home  >  Article  >  Backend Development  >  php中查询最近一个月的查询代码报错,请教咋办

php中查询最近一个月的查询代码报错,请教咋办

WBOY
WBOYOriginal
2016-06-13 12:58:12721browse

php中查询最近一个月的查询代码报错,请问咋办
//最近一月的订单
   $sql_month="select order_id , order_number from order_table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH)     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) ------解决方案--------------------
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)" 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn