前台搜索表单用select,提交后,在php里做判断,再进行搜索就行了.例子:<form action="searchpro.php" method="post" ><div class="search"><select name="CateId"> <option value ="1">Volvo</option> <option value ="2">Saab</option> </select><input name="searchkey" type="text" class="inputtext"/></div><div class="searchbutton"><button type="submit" name="submit" class="inputbutton" value=" "></button></div></form> <?php $CateId = $_GET['CateId']; $searchkey=$_GET['searchkey']; if($CateId==1'') { $where .= " and CateId in($all_CateId) and (ProName like '%$searchkey%')"; }if($CateId==2'') { $where.=" and (ProName like '%$searchkey%') and TuiJian =1";$pro_rs = mysql_query( "select * from pro where $where order by $SortBy limit $start_row, $pro_page_count" );} ?>
<option value ="1">Volvo</option>
<option value ="2">Saab</option>
</select><input name="searchkey" type="text" class="inputtext"/></div><div class="searchbutton"><button type="submit" name="submit" class="inputbutton" value=" "></button></div></form>
<?php
$CateId = $_GET['CateId'];
$searchkey=$_GET['searchkey'];
if($CateId==1'')
{
$where .= " and CateId in($all_CateId) and (ProName like '%$searchkey%')";
}if($CateId==2'')
{
$where.=" and (ProName like '%$searchkey%') and TuiJian =1";$pro_rs = mysql_query( "select * from pro where $where order by $SortBy limit $start_row, $pro_page_count" );}
?>
查询是选定查询条件 比如编号 然后输入具体的编号查询准确的某条数值
两类搜索条件互不干涉 互相独立于是我就写了两个from 指向不同的action 两个form里边有各自的提交按钮 没有用到js 就可以了
当然 你这个需求比较特殊 你是一个输入框那还是要用到JS 不过不用在提交上做文章 那样太麻烦可以在两个form中各放置一个隐藏域 而你的输入框哪个form都不属于 但是当你改动此输入框的内容的时候 用js同步将内容修改到两个form的隐藏域中 各提交各的 清晰 简单.
search.php<form name="search" method="post" action="search-action.php">
<select name="search_flag"><option value="taobao">淘宝</option><option value="web">本站</option></select>
<input name="keyword" type="text"/>
<input type="submit" value="submit" name="submit"/>
</form>search-action.php
$keyword = $_POST['keyword'];
$search_method = $_POST['search_flag'];
if (search_method == "taobao"){
//淘宝sql
}else{
//本站sql
}mysql_query($sql);
if ($search_method == "taobao"){