How to fetch record between particular date range using php

Discussion in 'PHP' started by fulljob, Jul 21, 2010.

  1. #1
    I am making hotel booking online application and for the booking i am using table like this

    hotelid, personname,startdate,enddate

    startdate is a date of check in and enddate is date of check out.

    I want to know if date is like this

    start date : 07/14/2010
    end date : 07/21/2010

    How can i find that room is book for 15-20 date too?
     
    fulljob, Jul 21, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Your description is vague??

    But if I understand you correcty; try this (it would check if a record exists with the specified start and end date):

    <?php
    //replace table_name with the name of your table
    $check = mysql_num_rows(mysql_query("SELECT * FROM table_name WHERE startdate = '07/14/2010' AND enddate = '07/21/2010'"));
    
    if ($check > 0) {
    echo "Record Exists";
    }
    ?>
    PHP:
     
    danx10, Jul 21, 2010 IP
  3. savageman123

    savageman123 Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If I understand it correctly, I think he would actually want "..WHERE startdate >= '07/14/2010' AND enddate <= '07/21/2010'" since if he would need to know if all the rooms are booked any day between or not as well
     
    savageman123, Jul 21, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Theirfore I thought the OP meant, (s)he'd like to check if the record exists with them specific rows?

    But if the OP did meant what you pointed out, then that would be the correct way to go.
     
    danx10, Jul 21, 2010 IP