Jump to content

Recommended Posts

here is what i am doing:

 

i have a calendar that was made using php...

 

calendar script:

<?php
define("ADAY", (60*60*24));
if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) {
$nowArray = getdate();
$month = $nowArray["mon"];
$year = $nowArray["year"];
} else {
$month = $_POST["month"];
$year = $_POST["year"];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"]; ?></title>
<head>
<body>
<h1>Select a Month/Year Combination</h1>
<form method="post" action="index.php?page=vac">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",  "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
	echo " selected";
}
echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=2008; $x<=2050; $x++) {
echo "<option";
if ($x == $year) {
	echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br/>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
      <strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
	if ($dayArray["mon"] != $month) {
		break;
	} else {
		echo "</tr><tr>\n";
	}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
	echo "<td> </td>\n";
} else {
	echo "<td>".$dayArray["mday"]."    </td>\n";
	$start += ADAY;
}
}
echo "</tr></table>";
?>

 

that displays the calendar wonderfully.

 

now, when there is a reservation made, the admin of the site will put in a check in and check out date.  those are stored in the db. 

i have been able to retrieve the data from the db and display in a table:

if (strlen($month) == 2)
{
<?php
//select date from
$sqla="SELECT * FROM reservations WHERE datefrom LIKE '$year-$month-__'";
$resulta = mysql_query($sqla) or die(mysql_error());
$numa = mysql_num_rows($resulta);

//select date to
$sqlb="SELECT * FROM reservations WHERE dateto LIKE '$year-$month-__'";
$resultb = mysql_query($sqlb) or die(mysql_error());
$numb = mysql_num_rows($resultb);
}
else
{
//select date from
$sqla="SELECT * FROM reservations WHERE datefrom LIKE '$year-0$month-__'";
$resulta = mysql_query($sqla) or die(mysql_error());
$numa = mysql_num_rows($resulta);

//select date to
$sqlb="SELECT * FROM reservations WHERE dateto LIKE '$year-0$month-__'";
$resultb = mysql_query($sqlb) or die(mysql_error());
$numb = mysql_num_rows($resultb);
}
if (($numa < 1) && ($numb < 1))
{
echo "NO RESERVATIONS FOUND";
}
else
{
echo "<table width='300' border='1' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td scope='col'><div align='center'>Site</div></td>
    <td scope='col'><div align='center'>Check In Date </div></td>
    <td scope='col'><div align='center'>Check Out Date </div></td>
  </tr>";

$i=0;
while ($i < $numa) 
	{
	$datefrom=mysql_result($resulta,$i,"datefrom");
	$dateto=mysql_result($resulta,$i,"dateto");
	$site=mysql_result($resulta,$i,"site");
	list($yearfrom, $monthfrom, $dayfrom) = split('[/.-]', $datefrom);
	list($yearto, $monthto, $dayto) = split('[/.-]', $dateto);
	$checkin=$monthfrom."-".$dayfrom."-".$yearfrom;
	$checkout=$monthto."-".$dayto."-".$yearto;

	echo "<tr><td><div align='center'>".$site."</div></td>
			   <td><div align='center'>".$checkin."</div></td>
			   <td><div align='center'>".$checkout."</div></td></tr>";

	$i++;
	}
echo "</table>";

echo "<br><br><div align='center'>What would you like to do now?<br><a href='index.php?page=search'>Search For Another Reservation</a> <--||--> <a href='index.php'>Return To Main Page</a>";

}

?>

 

but i do not know how i can get the results to go on to the calendar, or how to make an array...much help needed, any help appreciated...thanks in advance.

 

ps.  if you want to see the script in action...i is located at http://www.everkleen.biz/resort/literes/index.php

username=test

password=d

here is my code now...

<?php
include "inc/dbconnect.php";
//error_reporting(0);

echo "<div align='right'><a href='index.php'>Return To Main Page</a></div>";
define("ADAY", (60*60*24));
if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) {
$nowArray = getdate();
$month = $nowArray["mon"];
$year = $nowArray["year"];
} else {
$month = $_POST["month"];
$year = $_POST["year"];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"]; ?></title>
<head>
<body>
<h1>Select a Month/Year Combination</h1>
<form method="post" action="test.php">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",  "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
	echo " selected";
}
echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=2008; $x<=2037; $x++) {
echo "<option";
if ($x == $year) {
	echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<select name="site">
  <option value="%%" selected>ALL</option>
  <option value="1">Cabin 1</option>
  <option value="2">Cabin 2</option>
  <option value="3">Cabin 3</option>
  <option value="4">Cabin 4</option>
  <option value="5">Cabin 5</option>
  <option value="6">Cabin 6</option>
  <option value="7">Cabin 7</option>
  <option value="8">Camp/RV Site 1</option>
  <option value="9">Camp/RV Site 2</option>
  <option value="10">Camp/RV Site 3</option>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br/>
<?php
//database search
$site=(stripslashes(htmlentities(mysql_real_escape_string($_POST['site']))));
if (strlen($month) == 2)
{
//select date from
$sqla="SELECT * FROM reservations WHERE datefrom LIKE '$year-$month-__' AND site LIKE '$site'";
$resulta = mysql_query($sqla) or die(mysql_error());
$numa = mysql_num_rows($resulta);
}
else
{
//select date from
$sqla="SELECT * FROM reservations WHERE datefrom LIKE '$year-0$month-__'  AND site LIKE '$site'";
$resulta = mysql_query($sqla) or die(mysql_error());
$numa = mysql_num_rows($resulta);
}
if ($numa < 1)
{
echo "NO RESERVATIONS FOUND";
}
else
{
$i=0;
while ($i < $numa) 
	{
	$datefrom=mysql_result($resulta,$i,"datefrom");
	list($yearfrom, $monthfrom, $dayfrom) = split('[/.-]', $datefrom);
	$datefromarray=array($i => $dayfrom);

	$dateto=mysql_result($resulta,$i,"dateto");
	list($yearto, $monthto, $dayto) = split('[/.-]', $dateto);
	$datetoarray=array($i => $dayto);

	$site=mysql_result($resulta,$i,"site");


	$i++;
	}
	print_r(array_values($datefromarray));
	print_r(array_values($datetoarray));


}

$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
      <strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
	if ($dayArray["mon"] != $month) {
		break;
	} else {
		echo "</tr><tr>\n";
	}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
	echo "<td> </td>\n";
} else {
	if (($count > ($dayfrom - 1)) && ($count < $dayto))
		{echo "<td bgcolor='#000000'>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}
	else
		{
		echo "<td>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}
}
}
echo "</tr></table>";


?>
</body>
</html>

 

i have moved the db queries up above the calendar... i also changed this:

		if (($count > ($dayfrom - 1)) && ($count < $dayto))
		{echo "<td bgcolor='#000000'>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}
	else
		{
		echo "<td>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}

 

here is a link to the test page:

http://www.everkleen.biz/resort/literes/test.php

 

it doesnt get the end date right (always 2 days off), and it only shows one reservation per month...

 

looking at the php.net page for the next() array function i found this:

<?php

$my_array = explode(',','a,b,c,d,e,f,g');

$ary =& $my_array;

// Note: foreach(&ary => $a) wont work! Thats a little bit pity... :(

foreach($ary as $a){

    print 'letter ' . $a;

    if(next($ary)){

        unset($ary[count($ary) - 1]);

        print '<br>';

    }else{

        print '<br>dun!';

    }

}

?>

 

would i have to do something like this to have multiple reservations highlighted???

 

thanks again.

ok...now i am really stuck.

 

i have figured out how to capture the array...

now i need help with the script itself.

 

problem code:

	if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
	echo "<td> </td>\n";
} else {
	if (($count >=($arrayfrom[0])) && ($count <= ($arrayto[0])))
		{echo "<td bgcolor='#000000'>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}
	else
		{
		echo "<td>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}

 

i have the array displayed above the calendar.  when looking at the array, it looks like the 23rd through the 30th should be blacked out, but the 19th through the 26th is.  4 days behind.  i could have it be :

		if (($count >=($arrayfrom[0] + 4)) && ($count <= ($arrayto[0] + 4)))

but dont know if that would be the correct thing to do...

 

thanks

<<half bump>>

 

ok...i am just going to roll with the +4 solution unless anyone says anything otherwise...

		if (($count >=($arrayfrom[0]+4)) && ($count <= ($arrayto[0]+4)))
		{echo "<td bgcolor='#000000'>".$dayArray["mday"]."    </td>\n";
		$start += ADAY;
		}

 

now.  i need to know how to get more that just one reservation on the calendar.  i tried a while statement and it screwed up the whole calendar...

	if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
	echo "<td> </td>\n";
} else {
	$x=0;
	while ($x <= (count($arrayfrom)))
		{
		if (($count >=($arrayfrom[$x]+4)) && ($count <= ($arrayto[$x]+4)))
			{echo "<td bgcolor='#000000'>".$dayArray["mday"]."    </td>\n";
			$start += ADAY;
			}
		else
			{
			echo "<td>".$dayArray["mday"]."    </td>\n";
			$start += ADAY;
			}
		$x++;
		}
	}		
}

 

any suggestions yet???  anybody???  **crickets chirp**

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.