[英]how to get last weeks entry in mysql by using php
there is table in data base as P_order now i want fetch the last one weeks entry in that data base.... as i fetched the entry of the present date....but not able to fetch the last one week entry... 在数据库中有一个表,如P_order,我现在想在该数据库中获取最近一个星期的条目。...当我获取当前日期的条目时...。但无法获取最近一个星期的条目。 。
<?php
$wherecat = "`p_order_status` = 'active' AND `p_order_date` LIKE '".date('Y-m-d')."%' ";
$catsql =$general->GetRows('*' ,'p_order' ,$wherecat);
$catRes = mysql_num_rows($catsql);
?>
<p><?=$catRes;?></p>
<div class="box1">
<span class="li_cloud"></span>
<h3>Order Placed in Last Week</h3>
</div>
<?php
$wherecat1 = "`p_order_status` = 'active' AND `p_order_date` LIKE '".date('Y-m-d',strtotime('-1 day')). "%' ";
$catsql1 =$general->GetRows('*' ,'p_order' ,$wherecat1);
$catRes1 = mysql_num_rows($catsql1);
?>
<p><?=$catRes1;?></p>
Try something like this : 尝试这样的事情:
SELECT * FROM p_order WHERE p_order_date > DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
or 要么
SELECT * FROM p_order WHERE p_order_date > DATE_SUB(NOW(), INTERVAL 1 WEEK);
Try this code :- 试试这个代码:-
$wherecat1 = "`p_order_status` = 'active'
AND `p_order_date` >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND p_order_date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY ";
SELECT * FROM p_order WHERE date(p_order_date) > DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
要么
$wherecat1 = "`p_order_status` = 'active' AND date(`p_order_date`) > DATE_SUB(CURDATE(), INTERVAL 1 WEEK)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.