Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php搜索中使用两个选择选项_Php_Mysql - Fatal编程技术网

如何在php搜索中使用两个选择选项

如何在php搜索中使用两个选择选项,php,mysql,Php,Mysql,我的代码运行正常,但我有一个问题,我只能通过第一个选择选项进行搜索,而第二个选择选项不起作用,第一个选择选项($\u请求[“区域]”)”和 ($_REQUEST[“area”]“”)工作正常,但我只能通过 首先选择我写的选项,否则给我错误和更改时间 这些我有同样的问题,所以我想使用两个选择选项 过滤我的搜索 <?php if ($_REQUEST["string"]<>'') { $search_string = " AND (name LIKE '%".mysql_rea

我的代码运行正常,但我有一个问题,我只能通过第一个选择选项进行搜索,而第二个选择选项不起作用,第一个选择选项
($\u请求[“区域]”)”和
($_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>

因为您使用的是
类%…%
查询,所以根本不能使用索引,所以为什么不重写查询以使其更干净一点呢<代码>。。。其中像“%$query%”这样的concat(姓名、专业化、地址、电话、时间)
更容易理解,并且意味着查询中的重复数据要少得多。。并且可能会表现得和multi-like版本一样好。谢谢你,你是对的,但是我很抱歉我是一个初学者,所以你能写我如何重写这段代码吗。