tags:

views:

39

answers:

2

I'm making a website for my school and I need help with Mysql result. I need to know when is the gym available for use, ex : its busy from 2009-09-23 until 2009-09-30 and available all other dates, now I wrote a query but it aint workin.

   SELECT gym_name from gym, logs WHERE gym.gym_id = logs.logs_id 
    AND (gym.date_busy_from < '2009-09-23' 
    OR gym.date_busy_from > '2009-09-23' 
    AND gym.date_busy_till > '2009-09-30')

Can someone help me I'm stuck for hours, and I can't breach the wall. tnx

A: 

is the gym.date_busy_from stored in varchar format, or Date format? That would matter on your comparison. I don't see your parenthesis closed after the first AND statement.

contactmatt
Never mind, I see the closed parenthesis. My idea would be the comparison. Personally I would wrap all the where statements in there own sets of parenthesis.
contactmatt
its DATE format, I edited post 2 times maybe you didn't see it . Parenthesis is there, maybe I need to add another somewhere ?
Bob
+1  A: 

Yours. What does the OR condition do or what are you trying to do with it?

SELECT gym_name from gym, logs 
WHERE gym.gym_id = logs.logs_id 
AND (gym.date_busy_from < '2009-09-23' 
OR gym.date_busy_from > '2009-09-23'
AND gym.date_busy_till > '2009-09-30')

Try

SELECT gym_name 
FROM gym, logs
WHERE gym.gym_id = logs.logs_id
AND gym.date_busy_from < CURDATE()
AND gym.date_busy_till > DATE_ADD(CURDATE(), INTERVAL 7 DAY)

Or

SELECT gym_name 
FROM gym, logs
WHERE gym.gym_id = logs.logs_id
AND gym.date_busy_from > CURDATE()
AND gym.date_busy_till < DATE_ADD(CURDATE(), INTERVAL 7 DAY)
Phill Pafford