一个下拉菜单,一个文本框.
<?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>'.' <a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return delconfirm()">删除</a> '.' <a href="upedit.php?hid='.$row['h_id'].'" >编辑</a> '.'</td>';
echo '</tr>';
}
echo "</table>";mysql_close($connection); //关闭与数据库的连接
?>
<form method="POST" action="">
<table width="400"><tr align="left"><td align="left"> 搜索条件:<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=""/>
<input name="sousuo" type="submit" value="搜索"/></td></tr>
</table>
</form>
<?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>'.' <a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return delconfirm()">删除</a> '.' <a href="upedit.php?hid='.$row['h_id'].'" >编辑</a> '.'</td>';
echo '</tr>';
}
echo "</table>";mysql_close($connection); //关闭与数据库的连接
?>
<form method="POST" action="">
<table width="400"><tr align="left"><td align="left"> 搜索条件:<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=""/>
<input name="sousuo" type="submit" value="搜索"/></td></tr>
</table>
</form>
这个删掉。
或者在程序里验证下$ziduan是否为空
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>'.' <a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return delconfirm()">删除</a> '.' <a href="upedit.php?hid='.$row['h_id'].'" >编辑</a> '.'</td>';
echo '</tr>';
}
你这个不是在输出吗?
$maxRowCount=mysql_num_rows($result);//这句应该放在这里
$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 '%%'当然会查出所有的记录了
否则就成了where `{$ziduan}` like '%%'
那和where 1或不要where有什么区别????
$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>'.' <a href="delect_sj.php?hid='.$row['h_id'].'" onclick="return delconfirm()">删除</a> '.' <a href="upedit.php?hid='.$row['h_id'].'" >编辑</a> '.'</td>';
echo '</tr>';
}
echo "</table>";
}}
mysql_close($connection); //关闭与数据库的连接
$query = "SELECT * FROM hotel_activities_2 where $ziduan like '%{$txt_sousuo}%'";