Hi.
I've searched a bit around the different boards on PHPbuilder, but i cannot find an answer to my questions yet.

I'm familiar with easy php/mysql-applications, but i've run into a problem now. I'm trying to build a booking system(for training purpose), and I'm kind of stuck when it comes to this:
each booking record in db has a "from" and a "to" date(DATE format)
how can i return available objects when a user searchs for "available objects from 2006.01.01 to 2006.03.01 ?

help would be much appreciated.

    You don't say how you want the match to be made.

    If you want the dates to match exactly:

    $query = "SELECT * " .
             "FROM my_table " .
             "WHERE `from` = '" . $from_date . "' AND `to` = '" . $to_date . "'";

    or, if you want the selected range to be completely within the given range:

    "WHERE `from` <= '" . $from_date . "' AND `to` >= '" . $to_date . "'";

    or, if you want the any part of the selected range to be within the given range:

    "WHERE (`from` <= '" . $to_date . "' AND `to` >= '" . $from_date . "') " .
       "OR (`to` >= '" . $from_date . "' AND `from` <= '" . $to_date . "')";

    Etc.

      Tnx. The solution seems to have solved my problem so far(it was the last sql I was looking for).

        Write a Reply...