ThinkPHP implements Multi-field fuzzy match query, thinkphp Field
The example in this article describes how thinkPHP implements Multi-field fuzzy match query. We will share this with you for your reference. The details are as follows:
Introduction: Sometimes the query must match multiple fields. For example, the query address is composed of multiple fields. There are provinces, cities, districts, and so on, as well as detailed addresses. How can I query the data at this time?
Implement the same query conditions for different fields
$ User = M ("User"); // instantiate the User object $ map ['name | title'] = 'thinkphp '; // input the query condition into the query method $ User-> where ($ map)-> select ();
Projects used
If ($ address) {// address query $ where ['B. province | B. city | B. area | B. detail '] = array ('like',' % '. $ address. '%'); $ this-> assign ('address', $ address );}
This is a simple and accurate solution.
The generated SQL statement is as follows:
SELECT. *, B .name, B .tel, B .province, B .city, B .area, B .detail, B .zip codeFROM sh_order aLEFT JOIN sh_member_address B on. member_id = B. member_id and B. selected = 1 WHERE ('store _ id' = '10') AND (. member_id IN ('7') AND (B. province LIKE '% sucheng %') OR (B. city LIKE '% sucheng district %') OR (B. area LIKE '% sucheng district %') OR (B. detail LIKE '% sucheng district %') order by addtime desc, sendtime asc, paytime descLIMIT
From the SQL statement, we can see that the parentheses, AND, OR combinations in the where clause are clever.
As follows: