Ciao a tutti, sto mettendo a punto uno script per le prenotazioni ed ho un problema con associare le date di check.in & check-out con la tabella dei prezzi allego il codice dello script:
Questa invece e' la tabella prezzi:
in pratica lo script recupera i prezzi di base settimanali e li associa ai vari giorni della settimana, per ogni lunedì associa `price_monday`e via dicendo, io vorre ad esempio aggiungere dei prezzi diversi un offerta per il fine settimana che va ad esempio da sabato 13 aprile a domenica 14 aprile, ma non so combinarlo nella query "SELECT * FROM PREZI....." mi date una dritta ragazzi?
Grazie
PHP:
<?php
session_start();
if(!isset($_GET['id'])){
header("Location:index.php");
}
if(!isset($_SESSION['to'])||!isset($_SESSION['from'])){
header("Location:index.php");
}
if($_SESSION['to']<=$_SESSION['from']){
header("Location:index.php");
}
include "configuration.php";
$con=mysql_connect($location,$username,$password);
mysql_select_db($database_name);
mysql_set_charset('utf8',$con);
$query="DELETE * FROM booking WHERE expires<'".date("Y-m-d H:i:s")."'";
mysql_query($query);
?>
<input type="hidden" name="facilitiesvalues" id="facilitiesvalues" value="<?php echo $valuesfield;?>">
</div><BR><BR>
</div>
<div id="fields">
<div id="roomsfields">
<table width="100%">
<tr style="font-weight:bold"><td><?php echo get_word($lang,"Tipo Camera")."</td><td>".get_word($lang,"Disponibilità")."</td><td>".get_word($lang,"Prezzo")."</td><td>".get_word($lang,"No di Camere")."</td>";
$i=0;
$roomsbooked=array();
$ratestable=array();
$query="SELECT * FROM camere WHERE idhotel='".$_GET['id']."'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$roomsbooked[$row['camera']]=0;
for($i=0;$i<8;$i++)
$ratestable[$row['camera']][$i]=0;
}
$query="SELECT * FROM prezzi WHERE idhotel='".$_GET['id']."'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$ratestable[$row['camera']][0]=$row['default_price'];
$ratestable[$row['camera']][1]=$row['price_monday'];
$ratestable[$row['camera']][2]=$row['price_tuesday'];
$ratestable[$row['camera']][3]=$row['price_wednesday'];
$ratestable[$row['camera']][4]=$row['price_thursday'];
$ratestable[$row['camera']][5]=$row['price_friday'];
$ratestable[$row['camera']][6]=$row['price_saturday'];
$ratestable[$row['camera']][7]=$row['price_sunday'];
}
$from=array();
$tok=strtok($_SESSION['from'],"-");
while($tok){
$from[]=$tok;
$tok=strtok("-");
}
$to=array();
$tok=strtok($_SESSION['to'],"-");
while($tok){
$to[]=$tok;
$tok=strtok("-");
}
$query="SELECT * FROM booking WHERE idhotel='".$_GET['id']."' AND
((check_in<='".$from[2]."-".$from[1]."-".$from[0]."' AND check_out>='".$from[2]."-".$from[1]."-".$from[0]."') OR
(check_in>='".$from[2]."-".$from[1]."-".$from[0]."' AND check_out<='".$to[2]."-".$to[1]."-".$to[0]."') OR
(check_in<='".$from[2]."-".$from[1]."-".$from[0]."' AND check_out>='".$to[2]."-".$to[1]."-".$to[0]."') OR
(check_in<'".$to[2]."-".$to[1]."-".$to[0]."' AND check_out>='".$to[2]."-".$to[1]."-".$to[0]."'))";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$roomsbooked[$row['camera']]++;
}
while(($row=mysql_fetch_array($roomsresult))!=NULL){
$roomsleft=$row['quantita']-$roomsbooked[$row['camera']];
echo "<tr><td>".$row['camera']."</td><td>".$roomsleft."</td>";
$price=0;
$_SESSION['totaldays']=0;
$date=strtotime($from[2]."-".$from[1]."-".$from[0]);
while($date<strtotime($to[2]."-".$to[1]."-".$to[0])){
$_SESSION['totaldays']++;
$dayofweek=date("N",$date);
if($ratestable[$row['camera']][$dayofweek]!=0)
$price+=$ratestable[$row['camera']][$dayofweek];
else
$price+=$ratestable[$row['camera']][0];
$date+=86400;
}
echo "<td><div id=\"price".$row['camera']."\">".$price."</td></div>";
?>
<form name="roomsform" id="roomsform" method="POST" action="bookroom.php?roomtype=<?php echo $row['room_type']."&hid=".$_GET['hid']; ?>">
<?php
if($roomsleft<=0)
$disabled="disabled";
else
$disabled="";
echo "<td><select name=\"numberofrooms".$row['camera']."\" style=\"width:40px\" ".$disabled." id=\"numberofrooms".$row['camera']."\" onchange=\"getPrice(this.value,".$price.",'".$row['camera']."');\">";
$_SESSION['price'.$row['camera']]=$price;
for($i=1;$i<=$roomsleft;$i++){
echo "<option value=\"".$i."\">".$i."</option>";
}
echo "</select></td>";
echo "<td><input type=\"submit\" ".$disabled." name=\"submit".$row['camera']."\" id=\"submit".$row['camera']."\" value=\"".get_word($lang,"Book!")."\"></td>";
echo "</tr>";
echo "</form>";
}
?>
Questa invece e' la tabella prezzi:
Codice:
CREATE TABLE `prezzi` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`idhotel` int(11) NOT NULL,
`inizio` date NOT NULL,
`fine` date NOT NULL,
`camera` varchar(255) NOT NULL,
`default_price` int(4) NOT NULL DEFAULT '0',
`price_monday` int(4) DEFAULT '0',
`price_tuesday` int(4) DEFAULT '0',
`price_wednesday` int(4) DEFAULT '0',
`price_thursday` int(4) DEFAULT '0',
`price_friday` int(4) DEFAULT '0',
`price_saturday` int(4) DEFAULT '0',
`price_sunday` int(4) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idhotel` (`idhotel`),
KEY `camera` (`camera`)
) ;
Grazie
Ultima modifica: