我现在有点卡住了,感谢一些帮助。我有一个带有 2 列“月”和“价格”的 Mysql 表,即 1 月 >> 5(欧元);二月>> 7(欧元)等等。在网站的预订表格上,用户可以选择到达日期和离开日期。如果用户选择一个介于其间的日期,例如 20.01.2013-12.04.2013,如何计算其间的完整月份(02 和 03)?
这是我必须计算到达和离开月份的天数:
...
$query="SELECT * FROM pricecal";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num)
{
$month=mysql_result($result,$i,"month");
$price=mysql_result($result,$i,"price");
$i++;
$a = $_POST['dropToDay'];
$b = $_POST['dropToMonth'];
$c = $_POST['dropToYear'];
$d = $_POST['dropOffDay'];
$e = $_POST['dropOffMonth'];
$f = $_POST['dropOffYear'];
$days_to = (date('t',mktime(0, 0, 0, $a,(date($b) +1), date($c))) - $a +1);
$off_month_dif = (date('d-m-Y',mktime(0, 0, 0, $d,(date($e)), date($f))) - $d);
$days_off = (date('d-m-Y',mktime(0, 0, 0, $d,(date($e)), date($f))) - $off_month_dif);
$days = (date($f.$e.$d) - date($c.$b.$a));
$days_all = ($days+1);
if($b==$e AND $b==$month)
{
$b = $month;
$pricing = $days_all*$price;
echo 'Price for '.$days_all.' days is '.$pricing.' EUR.';
}
if($b == $month AND $b != $e)
{
$pricing1 = $days_to*$price;
}
if($e == $month AND $b != $e)
{
$pricing = $days_off*$price;
$pricings_all = $pricing+$pricing1;
echo 'Price for booking time: '.$pricings_all.' EUR';
}
.....