我的查询工作正常,但我希望显示今天的日期数量+提前2天添加,并在今天的日期之后订购数据,然后是明天和之后的日期?
因为记录太多所以无法以其他格式更改 varchar 行meeting_date
这是MySQL查询
日期存储为月/日/年,如2016年1月1日。
$today = date("m/d/Y");
$query = "SELECT COUNT(*) as num FROM records WHERE meeting = 'Yes' AND (meeting_date LIKE '%".$today."%') ORDER BY id DESC";
$total_pages = mysql_fetch_array(mysql_query($query));
感谢您的时间和帮助。
答案 0 :(得分:1)
尝试
$today = date("m/d/Y");//today's date
$after2days = date('m/d/Y', strtotime("+2 days"));//2 days from now
$query = "SELECT COUNT(*) as num FROM records WHERE meeting = 'Yes' AND meeting_date BETWEEN '".$today."' AND '".$after2days."' ORDER BY meeting_date";
我建议您不要使用mysql_ *函数,因为它们已被弃用。请使用mysqli_ *或PDO函数。
答案 1 :(得分:1)
你应该在获取日期时在php中执行此操作
$today = date("m/d/Y");
$tommarow= date('m/d/Y', strtotime("+1 days"));
$twoday= date('m/d/Y', strtotime("+2 days"));
$query = "SELECT COUNT(*) as num FROM records WHERE meeting = 'Yes' AND
(meeting_date = '".$today."' or meeting_date = '".$tommarow."' or
meeting_date = '".$twoday."') group by meeting_date ORDER BY meeting_date";
答案 2 :(得分:0)
你需要这样做:
// get 3 days used in the query
$today = date("m/d/Y");
$day1 = date("m/d/Y", time() + 86400 );
$day2 = date("m/d/Y", time() + 86400*2 );
// updated query without LIKE
$query = "SELECT COUNT(*) as num FROM records WHERE meeting = 'Yes' AND (meeting_date = '$today' OR meeting_date = '$day1' meeting_date = '$day2') ORDER BY id DESC";
需要使用php排序数组后。