select * from 酒店表 as a inner join 房型表 as b on a.hid = b.hid这个是SQL语句!PHP的语法我还没研究那!呵呵

解决方案 »

  1.   

    语句我会但是我不知道怎么再前台显示出来,以前搞.net现在开始PHP
      

  2.   


     //开始搜索
        $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;
            }这是我写的,不知道前台怎么显示
      

  3.   

    表一(酒店表)字段: 
    hid    name                  city     info           rid
    1       首都大酒店          北京    位于北京      1
    2       富丽华大酒店       大连    位于大连      1
    3      皇姑大酒店           沈阳    位于沈阳      2表二(房型表)字段: 
    rid     type            info                price 
    1        豪华房间    非常豪华          255 
    2        普通房价    一般                 100 
      

  4.   

    建议LZ先看一点基础的数据结构的书.高效的CODE是建立在高效的DATA结构之上的.
      

  5.   

    以这个两个表为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>";
    ?>
      

  6.   

    你搞错了吧,象你这样设计,一个酒店只有一种房? 所有酒店的豪华房价都一样?楼主的设计没有问题, 要知道, 房型表的type/info/price对不同酒店都是可能不一样的,楼主只是给的数据不清楚
      

  7.   

    LS,我已经说过了,要是有很多房间的话,你怎么弄?LZ只给出了两种房型,我当然只能按两种房型去给他改,虽然你所说的type/info/price不可能一样,但如果你仅从LZ给的字段和他表达的意思来看,他的那种表设计还会是没有问题的么?