简体   繁体   中英

Php search with multiple fields

I'm creating a php webpage search with mysql database ,

在此处输入图片说明

as you see on pic above my html search form I'm passing three values through POST .

PHP CODE:

<?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

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

WHERE (condition1 or condition2 or condition3) and condition4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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