亲爱的朋友,我有两个功能,也许我将来可能会有更多功能,但重点是当用户在同一文本字段上根据邮政编码搜索酒店时,应该调用函数 hotel_by_postel_code($textvalue) 并且当我根据国家搜索,然后应该调用函数 hotel_by_country($textvalue)。以下是应该显示结果的代码,但它根本没有显示结果。
<?php require_once("includes/header.php");?>
<?php require_once("includes/connection.php")?>
<?php
if(isset($_POST['submit'])){
$message ="";
$textvalue = $_POST['search'];
if(empty($allhotels = hotel_by_postel_code($textvalue)) || empty($allhotels = hotel_by_country($textvalue))){
$message = "There is no record in the database";
}
}else{
$allhotels = select_all_hotels();
}
?>
<div class="cBoth"></div>
<div id="sep"></div>
<div id="mainContentSection" class="Calign">
<div id="detaillist">
<div id="searching" class="Calign">
<form action="list2.php" method="POST" id="searchForm">
<fieldset>
<input type="text" name="search" />
<input type="submit" name ="submit" value="Search" /></fieldset>
</form>
</div><!--End of searching-->
<?php
if(isset($message)){
echo"<div id=\"listtitle\">";
echo"<h2>".$message."</h2>";
echo"</div>";//End of listtitle div
}else{
echo"<div id=\"listtitle\">";
echo"<h2>Property Name</h2> <h2>Location</h2> <h2>Guest Rating</h2><h2>Hotel Rank</h2><h2>Per night</h2>";
echo"</div>";
}
?><!--End of listtitle-->
<div class="cBoth"></div>
<?php
$i=0;
while($hotels_set = mysql_fetch_array($allhotels)){
$room_rate = rateforhotel($hotels_set['hotel_id']);
if(!empty( $hotels_set['hotel_name']) && ($room_rate['hotel_id'] == $hotels_set['hotel_id'] ) ){
if($i % 2 == 0) { echo "<div id=\"innerlisteven\">"; }
else
{
echo"<div id=\"innerlistodd\">";
}
echo"<h2><a href =\"#\">". $hotels_set['hotel_name'] ."</a></h2>";
echo"<h2>". $hotels_set['country'] ."</h2>";
if(!intval($hotels_set['star'])){
echo"<h2>". $hotels_set['star'] ."</h2>";
}else{
echo"<h2>". $hotels_set['star'] . "<img src=\"img/repetimg/star.png\"/></h2>";
}
echo"<h2>". $hotels_set['star'] . "</h2>";
echo"<h2>". $room_rate['rate'] . "</h2>";
echo"</div>";
$i++;
}//end of if()
}//end of hotel while
mysql_close($con);
?>
</div><!--End of details-->
<div id="advertlisting">
<div id="search">search menu</div>
</div><!--End of adverts left-->
</div><!--End of end of maincontent-->
<div class="cBoth"><!-- clear Both--></div>
<?php require_once("includes/footer.php"); ?>
以下代码是函数本身
function hotel_by_country($country){
global $connection;
$query = "SELECT * FROM Hotels WHERE country ='{$country}'";
$hotel_set = mysql_query($query,$connection);
confirm_query($hotel_set);
return $hotel_set;
}
function hotel_by_postel_code($postal){
global $connection;
$query = "SELECT * FROM Hotels WHERE hotel_postal_code ='{$postal}'";
$hotel_set = mysql_query($query,$connection);
confirm_query($hotel_set);
return $hotel_set;
}
function select_all_hotels(){
global $connection;
$query = "SELECT *
FROM Hotels";
$hotel_set = mysql_query($query,$connection);
confirm_query($hotel_set);
return $hotel_set;
}