• 技术文章 >后端开发 >php教程

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

    2016-06-13 11:06:02原创423
    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="" ;
    }
    查询最近一个月的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)"
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:nbsp order month DATE INTERVAL
    上一篇:关于隐藏表单的一个有关问题 下一篇:swfupload之前好的,现在异常500
    千万级数据并发解决方案

    相关文章推荐

    • mysql 正则查询信息,该如何处理 • 请教PHP连接oracle8i,如何配置 • 海内学习PHP的资源站点有哪些 • 最近有点迷惘,还想请大家指导上学习的方法 • 端口已处于监听状态,为什么 fsockopen还会失败,该怎么处理
    1/1

    PHP中文网