Query query code in PHP for the last one months error, ask what to do

Source: Internet
Author: User
Query query code in PHP for the last one months error, what should I do
Orders for the last January
$sql _month= "Select order_id, Order_number from order_table where Date_sub (Curdate (), INTERVAL INTERVAL 1 month) <= dat E (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= "There are no orders in recent month. " ;
}
else{
$str =mysql_fetch_array ($mysql _month);
$html _info_month= "Orders of the last January";
$html _info_month= "
      " ;
      do{
      er _id=iconv ("gb2312", "Utf-8//ignore", $str ["order_id"]);
      er _number=iconv ("gb2312", "Utf-8//ignore", $str ["Order_number"]);
      $html _info_month.= "
    • ". er _number."
    • " ;
      }while ($str =mysql_fetch_array ($mysql _month));
      $html _info_month.= "
" ;
}
Is it correct to query the SELECT statement for the last one months?
Error:
String (*) "Select order_id, Order_number from order_table where Date_sub (Curdate (), INTERVAL INTERVAL 1 MONTH) <= da Te (order_date) "Could not query. You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ') <= date (order_date) ' At line 1
------Solution--------------------
Select order_id, order_number from order_table where date > ". Strtotime ('-1 month ')
------Solution--------------------
1 actually you just want to ask that SQL, then don't put code, too much, many people do not like to see
2 $sql _month= "Select order_id, Order_number from order_table where Date_sub (Curdate (), INTERVAL INTERVAL 1 month) <= D Ate (order_date) "means to find out that the date of those orders plus one months is also less than the current date, and the last one months means that the order date is one months smaller than the current date, that is, the order date plus one months is greater than or equal to the current date, so should be a select order_id, order_number from order_table where Date_sub (Curdate (), INTERVAL INTERVAL 1 MONTH) >= DATE (order_date) "
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.