5

私はこのようなmysqlテーブルを持っています:

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 の間にあるユーザー名を取得しようとしています。

// $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']; 

しかし、それは単なる print username = 18 です。print 18 および 19 number username である必要があります。なぜ表示されないのですか?何か案が?

4

3 に答える 3

8

クエリ:

$search = mysql_query("SELECT username FROM oc_calendar WHERE 
start_date between '$from' AND '$to'");

また、複数のユーザー名と正しい SQL クエリを表示するには、while ループが必要です (上記を参照)。

while($re_search = mysql_fetch_array($search)) {
  $re_search['username'] . '<br>';
}
于 2013-03-15T17:17:06.043 に答える
1
SELECT username FROM oc_calendar WHERE start_date between '$from' AND '$to'
于 2013-03-15T17:11:05.040 に答える
0

このクエリを使用できます:

$search = mysql_query("SELECT username FROM oc_calendar WHERE start_date between '$from' AND '$to'"); 

ご使用の条件について:

where start_date >'$from'

fromdate = 2013-03-31 したがって、上記の条件は username = 19 には当てはまりません。代わりに、使用する必要があります

where start_date >= '$from' and startdate <='$to'
于 2013-03-15T17:09:53.957 に答える