Ciao a tutti, sto cercando di modificare uno script che mi calcola il prezzo di un hotel in base alla ricerca effettuata tra differenti date, lo script funziona bene solo che mi restituisce il totale del prezzo solo sull'ultimo prezzo inserito vi faccio un'esempio: ho la tabella prezzi con id,id_hotel, from, to, room_type, price, ho queste date: dal 10-05-13 al 12-05-13 il prezzo 100 poi dal 12-0513 al 14-05-13 il prezzo 50, se effettuo una ricerca dal dal 11 al 13 maggio invece di calcolare 150 mi calcola 100 praticamente ricava solo il valore dell'ultimo prezzo:
questo e' il codice:
Non riesco prorpio a capire dove e' lo sbaglio
Grazie
questo e' il codice:
PHP:
<?php
session_start();
if(!isset($_GET['hid'])){
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 "includes/configuration.php";
$con=mysql_connect($location,$username,$password);
mysql_select_db($database_name);
mysql_set_charset('utf8',$con);
include "includes/database_add.php";
include "includes/language.php";
//Set language
if(isset($_GET['lang'])){
$_SESSION['lang']=$_GET['lang'];
$lang=$_SESSION['lang'];
}else if(isset($_SESSION['lang'])){
$lang=$_SESSION['lang'];
}else{
$lang="English";
}
//end of set language
$query="DELETE * FROM book WHERE expires<'".date("Y-m-d H:i:s")."'";
mysql_query($query);
?>
<?php
$query="SELECT * FROM roomtypes WHERE hotel_id=".$_GET['hid'];
$roomsresult=mysql_query($query);
$roomsnum=mysql_num_rows($roomsresult)-1;
$query="SELECT * FROM hotel JOIN countries ON hotel.country_id=countries.id JOIN cities ON hotel.city_id=cities.id WHERE hotel_id='".$_GET['hid']."'";
$result=mysql_query($query);
$info=mysql_fetch_array($result);
?>
var roomnum=<?php echo $roomsnum;?>;
</script>
</head>
<body>
<div id="maincontent">
<h1><?php echo $info['name'];?></h1>
<div id="address">
<?php echo $info['hotel_address'].",".$info['city'].",".$info['country'];?>
</div>
<div id="fields">
<div id="roomsfields">
<table width="100%">
<tr style="font-weight:bold"><td><?php echo get_word($lang,"Room Type")."</td><td>".get_word($lang,"Available Rooms")."</td><td>".get_word($lang,"Price")."</td><td>".get_word($lang,"No of Rooms")."</td>";
$i=0;
$roomsbooked=array();
$ratestable=array();
$query="SELECT * FROM roomtypes WHERE hotel_id='".$_GET['hid']."'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$roomsbooked[$row['room_type']]=0;
for($i=0;$i<8;$i++)
$ratestable[$row['room_type']][$i]=0;
}
$from = $_GET['from'];
$to = $_GET['to'];
$hotel_id = $_GET['hid'];
$query = "SELECT id_hotel, room_type, price, (DATEDIFF($to, $from) * price) as total FROM rooms";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$ratestable[$row['room_type']][0]=$row['price'];
}
$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 book WHERE hotel_id='".$_GET['hid']."' 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['room_type']]++;
}
while(($row=mysql_fetch_array($roomsresult))!=NULL){
$roomsleft=$row['rooms_number']-$roomsbooked[$row['room_type']];
echo "<tr><td>".$row['room_type']."</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['room_type']][$dayofweek]!=0)
$price+=$ratestable[$row['room_type']][$dayofweek];
else
$price+=$ratestable[$row['room_type']][0];
$date+=86400;
}
echo "<td><div id=\"price".$row['room_type']."\">".$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['room_type']."\" style=\"width:40px\" ".$disabled." id=\"numberofrooms".$row['room_type']."\" onchange=\"getPrice(this.value,".$price.",'".$row['room_type']."');\">";
$_SESSION['price'.$row['room_type']]=$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['room_type']."\" id=\"submit".$row['room_type']."\" value=\"".get_word($lang,"Book!")."\"></td>";
echo "</tr>";
echo "</form>";
}
?>
</table>
</table>
</div>
</div>
<div style="clear:both"></div>
</div>
<?php
mysql_close($con);
?>
Grazie