我已经创建了一个酒店预订系统,我正在尝试添加多晚住宿选项。基本上,如果酒店决定在指定日期使用此选项,预订在这些日期预订的客人将需要预订酒店所需的一定数量的夜晚。例如,如果在2011年1月1日有3晚住宿要求,2011年1月1日预订的客人将需要一次入住至少3晚,并且预订于01/02 /的客人2011年必须一次至少入住2晚。
如果你从日期开始向前推进,我已经为此开发了代码,但它也需要倒退,因为在2010年12月31日停留也符合要求,而我在设计这个问题时遇到了麻烦。以下是我目前的HTML代码:
<form action='aaa' method='post' id='aaa'>
<h3>Minimum Stay Option</h3>
On <input type='text' size='15' maxlength='10' id='m' name='m' /> guests must stay minimum of <input type='text' size='10' maxlength='2' id='mn' name='mn' />* nights
<input type='submit' class='button' value='Update' /><br /><br />
<span style='font-size:12px; font-style:italic'>*If you wish to remove a minimum stay requirement, please enter each date for which there is a minimum stay requirement and enter "1" into the nights field.</span><br />
</form>
和php代码:
if(isset($_POST['m']) &&
isset($_POST['mn']))
{
$d = $_POST['m'];
$m = strtotime($d);
$mn = $_POST['mn'];
$max_date = $m + (($mn - 1) * 86400);
if ($mn == 0) echo "<div class='rates3'><span style='color:red'>The number of nights inputed must be greater than 0.</span></div>";
elseif ($mn == 1)
{
for ($m; $m <= $max_date; $m += 86400)
{
$date = date('m/d/Y', $m);
$table = 'foobar';
$query = "INSERT INTO $table(d, min) VALUES('$date', '') ON DUPLICATE KEY UPDATE min=''";
mysql_query($query);
}
echo "<div class='rates3'><span style='color:red'>You removed the minimum stay requirement for $d. Guests booking on that date will no longer have to stay more than one night.</span></div>";
}
else
{
for ($m; $m < $max_date; $m += 86400)
{
$date = date('m/d/Y', $m);
$table = 'foobar';
$query = "INSERT INTO $table(d, min) VALUES('$date', '1') ON DUPLICATE KEY UPDATE min='1'";
mysql_query($query);
}
echo "<div class='rates3'><span style='color:red'>You created a $mn nights minimum stay requirement on $md. Guests booking on $d will have to stay a minimum of $mn nights.</span></div><br />";
}
}