Page 1 of 1

whats wrong with this query ??

Posted: Fri Mar 02, 2007 10:19 am
by PHPycho
i am using this query and there is no result

Code: Select all

SELECT *
FROM `tb_bookingDate`
WHERE ('$fromDate' 
BETWEEN booking_from
AND booking_to)
OR ('$to'
BETWEEN booking_from
AND booking_to)
Using the above query as two (separated by OR) gives the required results
What's the problem in using the above query ?
Any Answers ??
Thanks[/syntax]

Posted: Fri Mar 02, 2007 10:32 am
by pickle
This is entirely an SQL question. Please post in the appropriate forum.

Moving thread.

As for your question - I'm really not sure. I've used BETWEEN...AND syntax before, but in all cases, I've supplied the range, rather than making the range defined by column values.

Posted: Fri Mar 02, 2007 10:33 am
by PHPycho
I apologize for my mistake..
Sorry

Posted: Fri Mar 02, 2007 10:53 am
by infolock
What are the values for $to and $fromDate ?

What are the field types for booking_from and booking_to ?

Posted: Fri Mar 02, 2007 1:06 pm
by PHPycho
$fromDate = date in Y-m-d (from user input)
$to = date in Y-m-d (from user input)
booking_form is of date type
booking_to is of date type

I apologize for my inadequacy

Posted: Fri Mar 02, 2007 1:16 pm
by infolock
no need to apologize.

have you tried echoing out your $sql ?

echo $sql;

Post us what it says. But before you do, open up whatever it is you use to access mysql (mysql query browser, console, or whatever), and put the same query in straight to mysql. mysql's error control will give you more insight as to what is going on with it. Post the error that mysql gives you, not php.

or, you could just put "or die(mysql_error())" at the end of your statement.

Code: Select all

$sql = "select * from blah";
$rst = mysql_query($sql) or die(MySQL_Error());