I am kind of stuck now and appreciate some help please. I have a Mysql table with 2 columns "month" and "price" i.e. January >> 5 (Euro); February >> 7 (Euro) and so on. On the booking form of the website the user can select arrival date and departure date. If the user selects a date with months in between, say 20.01.2013-12.04.2013, how can one calculate the full months (02 and 03) in between?
This is what i have got to calculate the days in arrival and departure months:
...
$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';
}
.....