简体   繁体   English

PHP搜索多个字段

[英]Php search with multiple fields

I'm creating a php webpage search with mysql database , 我正在使用mysql数据库创建php网页搜索,

在此处输入图片说明

as you see on pic above my html search form I'm passing three values through POST . 正如您在html搜索表单上方的图片中看到的那样,我正在通过POST传递三个值。

PHP CODE: PHP代码:

<?php 
$search_name =$this->filter($_POST["name"]);

  $search_location=$this->filter($_POST["location"]);

  $search_speciality=$this->filter($_POST["category"]);

  $sql="SELECT * FROM pro
        WHERE ('pro_fname' LIKE '%".$search_name."%') OR ('pro_speciality' LIKE '%".$search_speciality."%') OR ('pro_location' LIKE '%".$search_location."%') and Pro_category='Doctor'";

  ?>

Problem is I always get same result only the first one on database . 问题是我总是只能在数据库上得到第一个相同的结果。

even I let all fields empty . 甚至我让所有领域都空着。

Pro_category='Doctor' I used it to separate result because I have two categories Doctors and Pharmacies and this search is only performed against DOCTORS Pro_category='Doctor'我用它来区分结果,因为我有Doctors和Pharmacies两类,并且此搜索仅针对DOCTORS执行

我的意思是尝试正确地封装您的条件

WHERE (condition1 or condition2 or condition3) and condition4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM