0

I need to retrieve the records which are between the selected days(TWO dates are of two different fields in DB)

i tried this in php and its working

SELECT * FROM guest_info where check_in = '$check_in' and check_out= '$check_out';

but when i insert "between" noting happens

SELECT * FROM guest_info where check_in = '$check_in' and check_out= '$check_out' between '$check_in' AND '$check_out';

but its working well with mysql query... can sum1 help me with this issue? thanks :D

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by hardinera
0

I need to retrieve the records which are between the selected days(TWO dates are of two different fields in DB)

i tried this in php and its working

SELECT * FROM guest_info where check_in = '$check_in' and check_out= '$check_out';

but when i insert "between" noting happens

SELECT * FROM guest_info where check_in = '$check_in' and check_out= '$check_out' between '$check_in' AND '$check_out';

but its working well with mysql query... can sum1 help me with this issue? thanks :D

Hi, post more code please, where you get the vales $check_in and $check_out ? and explain with a little bit more details. I think if there are any two values into diff tables and you want to execute a sql and get some value according this. you can do something like this

$val1 = 1 //value from table1
$val2 = 2 // value from table 2

select * (or some value(s) ) from table1 (or table2) where val1 = '$val1'  AND '$val2' IN (select val2 from table2 );

something like this, but post more information and I will try to help you.
regards

0

Sounds more complicated than a simple between because you're checking two dates, not one.

You have a few scenarios that you could check, but you don't mention which one(s) you want to return:

consider:
$checkstart (entered parameter)
$checkend (entered parameter)

Your DB holds checkin and checkout dates.

RETURN OPTIONS
Set 1: all records where $checkstart and $checkend within checkin and checkout
Set 2: all records where $checkstart before checkin and $checkend after checkout
Set 3: all records where $checkstart and $checkend after checkout
Set 4: all records where $checkstart and $checkend before checkin
Set 5: all records where $checkstart before checkin and $checkend between checkin and checkout
Set 6: all records where $checkstart between checkin and checkout and $checkend after checkout

*Useful operators > and < , >= and <=, BETWEEN ... AND, NOT BETWEEN ... AND

0
$select = mysql_query("SELECT * FROM guest_info 
where  check_in >= ('$check_in') 
 and check_out <=('$check_out');  "

this is the code for between dates... thanks all ^_^

Edited by hardinera: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.