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) "