简体   繁体   中英

Sql query with multiple clauses

I have a search form something like 在此处输入图片说明

My Database table looks like

在此处输入图片说明

If user type compay name and city i can search that using

if (!empty($_POST["company"]) && !empty($_POST["city"])) { 
    $company = mysqli_real_escape_string($conn,$_POST["company"]) ;
     $city = mysqli_real_escape_string($conn,$_POST["city"]) ;
    $result = mysqli_query($conn, "SELECT * FROM companies_active_accounts WHERE Company_Name='$company' AND City='$city'");

  }

But I want such a query that first box should contain company but second box can contain city or state. How to write query for that so that it searches for company with city/state.

Since city/state are same box. I have given the input field name of "city".

Thank You very much!

you could use a or condition

SELECT * 
FROM companies_active_accounts 
WHERE Company_Name='$company'
 AND ( City='$city' OR State = '$city')

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