5

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

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

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?

3 Answers 3

8

Query:

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

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>';
}
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT username FROM oc_calendar WHERE start_date between '$from' AND '$to'

Comments

0

You can use this query :

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

Regarding the condition that you are using :

where start_date >'$from'

your fromdate = 2013-03-31 so the above mentioned condition is not true for username = 19. Instead you should use

where start_date >= '$from' and startdate <='$to'

1 Comment

Well, your update query is not show the 18 and 19 number username.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.