whats wrong with this query ??

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

whats wrong with this query ??

Post 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]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Last edited by pickle on Fri Mar 02, 2007 10:34 am, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

I apologize for my mistake..
Sorry
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

What are the values for $to and $fromDate ?

What are the field types for booking_from and booking_to ?
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post 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
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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());
Post Reply