PHP +Mysql question

Discussion in 'Web Design & Coding' started by Eagle710, Nov 25, 2007.

  1. Eagle710

    Eagle710 OSNN Senior Addict

    Messages:
    312
    Location:
    Toronto, Ontario, Canada
    I am making a site that books cottage rentals. On my booking page i accept a check in and check out date i verify that they are valid dates, not in the past and that the Checkout date is greater then the check in. Im stuck now because i have to check my availability table to see if those days interfere with someone else's booking. I am having a hard time so i turn to you people of OSNN. Please. Is there a function that checks for overlapping in php or mysql. Or does anyone know some code to fix this problem. Thanks.
     
  2. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    Something along the lines of

    SELECT * FROM bookings WHERE cottage = '5' AND checkin BETWEEN :client_checkin AND :client_checkout AND checkout BETWEEN :client_checkin AND :client_checkout;

    Replacing :client_checkin and :client_checkout with the checkin/checkout dates specified by the client. Try throwing that SQL at some test data and see if you get the response you are looking for.
     
  3. Eagle710

    Eagle710 OSNN Senior Addict

    Messages:
    312
    Location:
    Toronto, Ontario, Canada
    That somewhat works but if the "stupid" client was to put a day in between the Arrival and Departure Date? i checked and that would fail the test. I'm surprised MYSQL doesn't just have function.