tags:

views:

92

answers:

3

I have written a simple mysql search form that searches between two dates. This query working perfect:

$sql = "SELECT * FROM table WHERE  dateStarted like '%$checkin%' 
AND dateEnded like '%$checkout%'";

But with

$sql2 = "SELECT * FROM table WHERE  dateStarted = $checkin 
AND dateEnded = $checkout";

There is no any result? What is difference between two sql?

Edit:

$checkin and $checkout are date (16-07-2010) 

Thanks in advance

+2  A: 

One matches the value of the variable $checkin, the other matches anything containing the value of the variable $checkin.

So if $checkin is foo, then the first will match "foo" or "something foosomething" while the second will match only "foo".

David Dorward
+5  A: 

$checkin and $checkout are date (16-07-2010)

Try putting quotes in your query:

$sql2 = "SELECT * FROM table WHERE  dateStarted = '$checkin'
         AND dateEnded = '$checkout'";
Sarfraz
yes quotes, dates are not number! Thanks
phpExe
@phpExe: You are welcome...
Sarfraz
A: 

"like" is for text and "=" for numbers and so on

Fincha
Not the case at all. Learn MySQL before making such comments.
Paul Dragoonis
i have just repeated the words of my teacher... its not only about mysql its about the hole think like DB. Yes you can search numbers with "like" but it isn't clear...
Fincha