Hello everybody,

I've got a good one for ya'll! Here's what I have. I have an HTML 
form with six list menus and a Submit button. This page is called 
whatsavailable.html. The menus in the form allow a user to select a 
date range and then submit the form to query my database. The form 
is submitted and the HTML code is passed through datec.php for 
processing. See the form code and PHP code below to see what list 
menus are included, and what I need help figuring out.

Basically, I have an availability calendar that sets property 
availability to reserved or available (not in those exact words). I 
am using a script which actually gets the value of the date I want 
to set as reserved or available, which updates my table field 
(rentaldate) with the actual date for a given "available" 
or "unavailable" status for a rental property. The property owner 
specifies which dates to set as reserved by checking checkboxes that 
hold the value of the actual date on the calendar. (e.g. 
checked="0000-00-00" and unchecked=""). Of course, the zeros would 
be replaced with an actual date in the same format.

The part I am needing help with is as follows:

1) When a renter specifies the date they want to arrive at the 
rental property (Arrival Date) and the date they want to leave the 
rental property (Departure Date), and then does a search by that 
particular date range, tell me how to get the date values between 
the arrival date and the departure date.

For example, if the renter specifies...

Arrival Date = January 20, 2006 (01/20/2006)
Departure Date = January 25, 2006 (01/25/2006)

How do I get the values of January 21, January 22, January 23, and 
January 24? I need to know how to get the dates in between the 
Arrival Date and Departure Date. I'm thinking that this can be done 
by using an array, but I have no understanding of how to do this 
myself. I really struggle with arrays in their most simple form!

2) View the PHP code below to see if I have used a practical method 
for achieving what I am trying to do in the first place.

3) Provide PHP code which will allow me to determine which dates in 
my calendar table are "Available dates" and which dates 
are "Unavailable dates". Available dates fields will be empty. (e.g. 
calendar.rentaldate = ""). Unavailable dates will have dates in 
them. (e.g. calendar.rentaldate = 2006-03-20). The property owner is 
updating the calendar.rentaldate fields in the database from an 
availability calendar by placing a check in checkboxes to reserve 
their property for specific dates. FYI, the checkboxes hold the 
value of rentaldate. So when the updated calendar is submitted, the 
checkbox values are written to the database, where they update the 
rentaldate fields based on the property owner's input.

This is where it gets tricky for me!!!

4) Create conditional statement that checks the calendar table in 
the database for Available dates. In other words, this bit of code 
should check to see if the specified date values are not present in 
the rentaldate fields. If the property is Available for "all dates" 
during the date range specified, display rental property details 
(e.g. link to rental property's Web page ad, etc.).

5) Create conditional statement that checks the calendar table in 
the database for Unavailable dates. In other words, this bit of code 
should check to see if "any" of the specified date values are 
present in the rentaldate fields. If the property is Unavailable for 
any of the dates during the date range specified, display "No 
Results Found!".

NOTE: If any dates are not available during a date range the renter 
specifies as the criteria for their search, the query should result 
in "No Results Found!". This is because even though there may be 
dates that the rental property is available during the specified 
date range, some of them may not be available. It makes sense to me 
that a property with only some of the available dates requested is 
still not a good match for the renter.


**********************
 Begin HTML Form Code
**********************

<form name="dates" action="datec.php" method="POST">
<p>
  Arrival Date:
  <select name="startmonth">
    <option value="01" selected>January</option>
    <option value="02">February</option>
    <option value="03">March</option>
    <option value="04">April</option>
    <option value="05">May</option>
    <option value="06">June</option>
    <option value="07">July</option>
    <option value="08">August</option>
    <option value="09">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>
  </select>
  <select name="startday">
    <option value="01" selected>1</option>
    <option value="02">2</option>
    <option value="03">3</option>
    <option value="04">4</option>
    <option value="05">5</option>
    <option value="06">6</option>
    <option value="07">7</option>
    <option value="08">8</option>
    <option value="09">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
  </select>
  <select name="startyear">
    <option value="2006" selected>2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
  </select>
</p>
<p>
  Departure Date:
  <select name="endmonth">
    <option value="01" selected>January</option>
    <option value="02">February</option>
    <option value="03">March</option>
    <option value="04">April</option>
    <option value="05">May</option>
    <option value="06">June</option>
    <option value="07">July</option>
    <option value="08">August</option>
    <option value="09">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>
  </select>
  <select name="endday">
    <option value="01" selected>1</option>
    <option value="02">2</option>
    <option value="03">3</option>
    <option value="04">4</option>
    <option value="05">5</option>
    <option value="06">6</option>
    <option value="07">7</option>
    <option value="08">8</option>
    <option value="09">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
  </select>
  <select name="endyear">
    <option value="2006" selected>2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
  </select>
</p>
<p><input type="Submit" name="Submit" value="Show Availability">
</p>
</form>

**********************
 End HTML Form Code
**********************

**********************
 Begin PHP Code
**********************

// This is the PHP code I have so far to help, even if a little!
// I am still learning, so please go easy on me!!! :-)

<?php
        include("dbconnect.php");
        $connection = mysql_connect($host,$user,$password)
                        or die ("Could Not Connect To Server.");
        $db = mysql_select_db($database,$connection)
                        or die ("Could Not Select Database.");

// POST Form Values.

        $startmonth     = $_POST['startmonth'];
        $startday       = $_POST['startday'];
        $startyear      = $_POST['startyear'];
        $endmonth       = $_POST['endmonth'];
        $endday         = $_POST['endday'];
        $endyear        = $_POST['endyear'];

// Format date variables (from the form) to look like 0000-00-00.
// This is how the dates are formatted in the database.

        $startdate      = date("$startyear" . "- . "$startmonth" . "-
" . "$startday");
        $enddate        = date("$endyear" . "-" . "$endmonth" . "-
" . "$endday");

// Query the database to select all rental properties, regardless of 
whether or not they are available during the specified date range 
the renter submits from the HTML form. 

                $query  = "SELECT propertyid FROM calendar WHERE 
rentaldate >= '$startdate' AND rentaldate <= '$enddate' GROUP BY 
propertyid";
                $result = mysql_query($query)
                                or die ("Could Not Retrieve 
Availability Dates.");
                $numrows = mysql_num_rows($result);

        $date1          = date($startdate); 
        $date2          = date($enddate); 

                function date_diff($start,$end)
                {
                return((strtotime($end) - strtotime($start))/86400);
                }

        echo "<font face='Arial' size='4'><b>Arrival 
Date:</b></font>&nbsp;<font face='Arial' size='3'>$date1</font><br>";
        echo "<font face='Arial' size='4'><b>Departure 
Date:</b></font>&nbsp;<font face='Arial' 
size='3'>$date2</font><br><br>";
        echo "<font face='Arial' size='4'><b>Total Length of 
Stay:</b></font>&nbsp;<font face='Arial' size='3'>"; echo date_diff 
("$startdate", "$enddate"); echo "&nbsp;Night(s)</font><br><br>";
        echo "<font face='Arial' size='4'><b>Search 
Results:</b></font>&nbsp;<font face='Arial' size='3'>There are 
$numrows vacation rentals that matched your search 
criteria.</font><br><br>";

// Don't laugh! I get totally lost here and have no earthly idea 
what I am doing! :-)

                while ($row = mysql_fetch_array($result))
                        {
                        extract($row);
                if ($_REQUEST[$rentaldate == "%0000-00-00"]) {
                echo "<font face='Arial' size='4' 
color='#CC0000'><b>No results found!</b><br><br><a 
href='whatsavailable.html'>Search Again...</a><br><br></font>";
                }
                else {
                echo "<font face='Arial' size='3'><a 
href='#'>Vacation Rental ID # $propertyid</a</font><br><hr size='1' 
width='100%'><br>";
                        }

                        }
?>

**********************
 End PHP Code
**********************


I need this done, if you can please help. I humbly request that you 
please don't send me to other links that will only confuse me (e.g. 
PHP manual, etc.). Remember, I don't have all the skills required to 
understand this type of logic, let alone trying to figure out what 
someone else has done that is completely different from what I need 
to get done. I am a do-it-yourselfer "Novice" wanna-be programmer. I 
have no formal training in Programming Logic or SQL. I've done 
pretty well thus far with PHP & MySQL For Dummies. I depend on these 
groups a lot! Thanks in advance for any helpful information you can 
provide!!!!!

- William





The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to