0

我的代码工作正常,但我有一个问题,我只能通过第一个选择选项进行搜索,而第二个选择选项不起作用,第一个选择选项($_REQUEST["area"]<>'')" and " ($_REQUEST["area"]<>'')工作良好,但我只能通过我写的第一个选择选项来获取否则给我错误,当改变那些我有同样的问题,所以我想使用两个选择选项来过滤我的搜索。

<?php

if ($_REQUEST["string"]<>'') {
$search_string = " AND (name LIKE  '%".mysql_real_escape_string($_REQUEST["string"])."%' OR 
specialization LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR
address LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR
telephone LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR
time LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%'
)"; 
}



if ($_REQUEST["area"]<>'') {
$search_area = " AND   location_id='".mysql_real_escape_string($_REQUEST["area"])."'";  
}


if ($_REQUEST["category"]<>'') {
$search_category = " AND  cate_id='".mysql_real_escape_string($_REQUEST["category"])."'";   

}



else {
$sql = "SELECT * FROM informations WHERE  id>0".$search_string.$search_area.$search_category;
}


$sql_result = mysql_query ($sql) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)) {
?>
<tr>
<td><?php $sel_cate2 = "SELECT title FROM categories where id = ".$row['cate_id']." ";
    $done_cate2 = mysql_query($sel_cate2);
    $get2 = mysql_fetch_array($done_cate2);
          echo $get2["title"]; ?></td>
<td><?php $sel_cate2 = "SELECT location FROM locations where id =  ".$row['location_id']." ";
    $done_cate2 = mysql_query($sel_cate2);
    $get2 = mysql_fetch_array($done_cate2);
          echo $get2["location"]; ?></td> 
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["specialization"]; ?></td> 
<td><?php echo $row["address"]; ?></td>
<td><?php echo $row["telephone"]; ?></td>
<td><?php echo $row["time"]; ?></td>
  </tr>
<?php
}
} else {
?>
<tr><td colspan="5">No results found.</td>
<?php   
}
?>
</table>
4

0 回答 0