PHP MySQL的两个日期之间的搜索 [英] Php Mysql Search Between Two Dates
本文介绍了PHP MySQL的两个日期之间的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的mysql表:
I've mysql table like this:
id start_date username
1 2013-04-04 18
2 2013-03-31 19
3 2013-04-04 19
4 2013-04-02 19
5 2013-04-03 18
我正在尝试通过以下查询获取start_date在2013-03-31到2013-05-01之间的用户名:
I'm trying to get username where start_date is between 2013-03-31 to 2013-05-01 with following query:
// $from = 2013-03-31 and $to = 2013-03-01 (example)
$search = mysql_query("SELECT username FROM oc_calendar WHERE start_date >'$from' AND
start_date < '$to'");
$re_search = mysql_fetch_array($search);
echo $search_p_id = $re_search['username'];
但是它只是打印用户名= 18,应该是打印18和19的数字用户名.为什么它不显示?有什么主意吗?
But It's just print username = 18, It's should be print 18 and 19 number username. why it's doesn't show? Any idea?
推荐答案
查询:
$search = mysql_query("SELECT username FROM oc_calendar WHERE
start_date between '$from' AND '$to'");
您需要一个while循环来显示多个用户名和一个正确的SQL查询(请参见上文):
And you need a while-loop to display more that one username and a correct SQL-query (see above):
while($re_search = mysql_fetch_array($search)) {
$re_search['username'] . '<br>';
}
这篇关于PHP MySQL的两个日期之间的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文