This paper illustrates the method of thinkphp fuzzy matching query with multiple fields. Share to everyone for your reference, specific as follows:
Foreword: Sometimes the query matches more than one field. such as query address, the address is composed of several fields. There are provinces, cities, districts and so on, as well as detailed address. How do you inquire at this time?
To implement the same query criteria for different fields
$User = M ("User"); Instantiate the User object
$map [' name|title '] = ' thinkphp ';
The query condition is passed into the query method
$User->where ($map)->select ();
To use in a project
if ($address) {
//Address query
$where [' b.province|b.city|b.area|b.detail '] = array (' Like ', '% '. $address. ') %');
$this->assign (' address ', $address);
}
Here it is very simple to solve this demand, and very accurate.
The resulting SQL statement is as follows
SELECT A.*,b.name,b.tel,b.province,b.city,b.area,b.detail,b.zipcode from
sh_order a left
JOIN sh_member_ Address B on a.member_id = b.member_id and b.selected = 1
WHERE (' store_id ' = ' ") and (a.member_id in (' 7 ')) and ((b.province like '% Sucheng District% ") 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 desc LIMIT
As you can see from the SQL statement, the parentheses in the where, the and,or combination is ingenious.
Screenshot below
More interested readers of thinkphp related content can view the website topic: "thinkphp Introductory Course", "thinkphp template Operation Skill Summary", "thinkphp Common Method Summary", "The CodeIgniter Introductory Course", "CI ( CodeIgniter) Framework Advanced tutorials, introductory tutorials for the Zend framework Framework, Smarty Templates Primer tutorial, and PHP template technology summary.
I hope this article will help you with the PHP program design based on thinkphp framework.