//开始搜索 $sql = "SELECT hotelb.*,roomb.* FROM ".tname('hotelb')." hotelb left join ".tname('roomb')." roomb on hotelb.id =roomb.c_id WHERE hotelb.city LIKE '%$gets[txtCity]%' and hotelb.c_name LIKE '%$gets[txtHotelName]%' and hotelb.type LIKE '%$gets[rdoHotelType]%' and hotelb.level LIKE '%$gets[chkStarA]%' and hotelb.jddz LIKE '%$gets[address]%' and roomb.etprice >= $gets[txtPriceLow] and roomb.etprice<= $gets[txtPriceHigh] "; $query = $_SGLOBAL['db']->query($sql.' LIMIT 0, 100');//最多100条 while ($value = $_SGLOBAL['db']->fetch_array($query)) { $list[] = $value; }这是我写的,不知道前台怎么显示
表一(酒店表)字段: hid name city info rid 1 首都大酒店 北京 位于北京 1 2 富丽华大酒店 大连 位于大连 1 3 皇姑大酒店 沈阳 位于沈阳 2表二(房型表)字段: rid type info price 1 豪华房间 非常豪华 255 2 普通房价 一般 100
建议LZ先看一点基础的数据结构的书.高效的CODE是建立在高效的DATA结构之上的.
以这个两个表为DATA,我给你写了一小段CODE,基本上就这个意思,当然你也可以用SMARTY来把PHP和HTML分开来写.相关的位置你改动一下便可出来结果. <?php $site="localhost"; $name="phpdb"; $root="root"; $ps="1234"; $conn=mysql_connect($site,$root,$ps); mysql_select_db($name); mysql_query("set names gb2312;"); $query="select h.hid,h.name,h.city,h.info,r.type,r.price from hotel h,room r where h.rid=r.rid;"; $result=mysql_query($query,$conn); echo "<table border='1'>"; echo "<tr>"; echo "<td>ID</td>"; echo "<td>NAME</td> "; echo "<td>CITY</td>"; echo "<td>PRICE</td>"; echo "</tr>"; while ($row=mysql_fetch_array($result)) { echo "<td>".$row['hid']."</td>"."<td>".$row['name']."</td>"."<td>".$row['city']."</td>"."<td>".$row['price']."</td></tr>"; } echo "</table>"; ?>
//开始搜索
$sql = "SELECT hotelb.*,roomb.* FROM ".tname('hotelb')." hotelb left join ".tname('roomb')." roomb on hotelb.id =roomb.c_id WHERE hotelb.city LIKE '%$gets[txtCity]%' and hotelb.c_name LIKE '%$gets[txtHotelName]%' and hotelb.type LIKE '%$gets[rdoHotelType]%' and hotelb.level LIKE '%$gets[chkStarA]%' and hotelb.jddz LIKE '%$gets[address]%' and roomb.etprice >= $gets[txtPriceLow] and roomb.etprice<= $gets[txtPriceHigh] ";
$query = $_SGLOBAL['db']->query($sql.' LIMIT 0, 100');//最多100条
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$list[] = $value;
}这是我写的,不知道前台怎么显示
hid name city info rid
1 首都大酒店 北京 位于北京 1
2 富丽华大酒店 大连 位于大连 1
3 皇姑大酒店 沈阳 位于沈阳 2表二(房型表)字段:
rid type info price
1 豪华房间 非常豪华 255
2 普通房价 一般 100
<?php
$site="localhost";
$name="phpdb";
$root="root";
$ps="1234";
$conn=mysql_connect($site,$root,$ps);
mysql_select_db($name);
mysql_query("set names gb2312;");
$query="select h.hid,h.name,h.city,h.info,r.type,r.price from hotel h,room r where h.rid=r.rid;";
$result=mysql_query($query,$conn);
echo "<table border='1'>";
echo "<tr>";
echo "<td>ID</td>";
echo "<td>NAME</td> ";
echo "<td>CITY</td>";
echo "<td>PRICE</td>";
echo "</tr>";
while ($row=mysql_fetch_array($result))
{
echo "<td>".$row['hid']."</td>"."<td>".$row['name']."</td>"."<td>".$row['city']."</td>"."<td>".$row['price']."</td></tr>";
}
echo "</table>";
?>