一个下拉菜单,一个文本框.
<?php
$txt_sousuo=$_POST['txt_sousuo'];
$ziduan=$_POST['ziduan'];echo "<table  border=1 width=700>"; 
echo "<tr bgcolor=#0099CC><th>hotel_id</th><th>start_date</th><th>end_date</th><th>content</th><th>source</th><th>s_type</th><th>操作</th></tr>"; 
//查询数据
$maxRowCount=mysql_num_rows($result);
$result = "SELECT * FROM hotel_activities_2 where '$ziduan' '%$txt_sousuo%'";
$result=mysql_query($result) or die("查询失败");
//循环输出表中各个字段值
while ($row = mysql_fetch_assoc($result)) {
    echo '<tr>';
    echo '<td>'.$row['hotel_id'].'</td>';
    echo '<td>'.$row['start_date'].'</td>';
    echo '<td>'.$row['end_date'].'</td>';
    echo '<td>'.$row['content'].'</td>';
    echo '<td>'.$row['source'].'</td>';
    echo '<td>'.$row['s_type'].'</td>';
    echo '<td>'.'&nbsp;<a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return  delconfirm()">删除</a>&nbsp;'.'&nbsp;<a href="upedit.php?hid='.$row['h_id'].'" >编辑</a>&nbsp;'.'</td>';
    echo '</tr>';
}
echo "</table>";mysql_close($connection); //关闭与数据库的连接 
?>
<form method="POST" action="">
<table  width="400"><tr align="left"><td align="left">&nbsp;搜索条件:<select name="ziduan" style="width:100">
<option value="" selected="selected">请选择</option>
<option value="hotel_id">hotel_id</option>
<option value="content">content</option>
<option value="source">source</option>
<option value="s_type">s_type</option></td><td align="left">搜索关键字:<input name="txt_sousuo" type="text" value=""/>&nbsp;&nbsp;
<input name="sousuo" type="submit" value="搜索"/></td></tr>
</table>
</form>

解决方案 »

  1.   

    $result = "SELECT * FROM hotel_activities_2 where `$ziduan` like '%$txt_sousuo%'";
      

  2.   

    你最好把<option value="" selected="selected">请选择</option>
    这个删掉。
    或者在程序里验证下$ziduan是否为空
      

  3.   

    while ($row = mysql_fetch_assoc($result)) {
        echo '<tr>';
        echo '<td>'.$row['hotel_id'].'</td>';
        echo '<td>'.$row['start_date'].'</td>';
        echo '<td>'.$row['end_date'].'</td>';
        echo '<td>'.$row['content'].'</td>';
        echo '<td>'.$row['source'].'</td>';
        echo '<td>'.$row['s_type'].'</td>';
        echo '<td>'.'&nbsp;<a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return  delconfirm()">删除</a>&nbsp;'.'&nbsp;<a href="upedit.php?hid='.$row['h_id'].'" >编辑</a>&nbsp;'.'</td>';
        echo '</tr>';
    }
    你这个不是在输出吗?
      

  4.   

    $result=mysql_query($result) or die("查询失败");
    $maxRowCount=mysql_num_rows($result);//这句应该放在这里
      

  5.   

    你的代码应该加个
    $txt_sousuo=$_POST['txt_sousuo'];
    $ziduan=$_POST['ziduan'];
    if($ziduan!='' && $txt_sousuo!=''){
    echo "<table  border=1 width=700>"; 
    .....
    mysql_close($connection); //关闭与数据库的连接
    }$result = "SELECT * FROM hotel_activities_2 where `{$ziduan}` like '%{$txt_sousuo}%'";全部查出来了,应该是$txt_sousuo的值为空了吧,where `{$ziduan}` like '%%'当然会查出所有的记录了
      

  6.   

    $txt_sousuo当然为空,它是个文本框
      

  7.   

    $txt_sousuo要有内容才是真正的有条件限制!
    否则就成了where `{$ziduan}` like '%%'
    那和where 1或不要where有什么区别????
      

  8.   

    归根结底,sql语句都没拼接出来,乍样能查得出正确的数据?
      

  9.   

    还是不行
    $txt_sousuo=$_POST['txt_sousuo'];
    $ziduan=$_POST['ziduan'];
    if($ziduan!='' && $txt_sousuo!=''){
    echo "<table  border=1 width=700>"; 
    echo "<tr bgcolor=#0099CC><th>hotel_id</th><th>start_date</th><th>end_date</th><th>content</th><th>source</th><th>s_type</th><th>操作</th></tr>"; 
    //查询数据$query = "SELECT * FROM hotel_activities_2 where '{$ziduan}' like '%{$txt_sousuo}%'";
    $result=mysql_query($query) or die("查询失败");
    if (mysql_num_rows($result)>0){
    //循环输出表中各个字段值
    while ($row = mysql_fetch_array($result)) {
        echo '<tr>';
        echo '<td>'.$row['hotel_id'].'</td>';
        echo '<td>'.$row['start_date'].'</td>';
        echo '<td>'.$row['end_date'].'</td>';
        echo '<td>'.$row['content'].'</td>';
        echo '<td>'.$row['source'].'</td>';
        echo '<td>'.$row['s_type'].'</td>';
        echo '<td>'.'&nbsp;<a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return  delconfirm()">删除</a>&nbsp;'.'&nbsp;<a href="upedit.php?hid='.$row['h_id'].'" >编辑</a>&nbsp;'.'</td>';
        echo '</tr>';
    }
    echo "</table>";
    }}
    mysql_close($connection); //关闭与数据库的连接 
      

  10.   

    $query = "SELECT * FROM hotel_activities_2 where `{$ziduan}` like '%{$txt_sousuo}%'";干脆
    $query = "SELECT * FROM hotel_activities_2 where $ziduan like '%{$txt_sousuo}%'";