This paper describes the method of thinkphp to implement multi-field fuzzy matching query. Share to everyone for your reference, as follows:
Introduction: Sometimes queries are matched to multiple fields. For example, a query address, the address is composed of multiple fields. There are provinces, municipalities, districts and so on, as well as detailed addresses. How do you check this time?
Implement the same query criteria for different fields
$User = M ("User"); Instantiate the User object $map[' name|title ' = ' thinkphp ';//pass query condition into Query method $user->where ($map)->select ();
Used in the project
if ($address) { //Address query $where [' b.province|b.city|b.area|b.detail '] = array (' Like ', '% '. $address. ' %'); $this->assign (' address ', $address);}
This is a simple solution to this requirement, and it is very precise.
The resulting SQL statement is as follows
SELECT a.*,b.name,b.tel,b.province,b.city,b.area,b.detail,b.zipcodefrom sh_order aleft JOIN sh_member_address B on a.member_id = b.member_id and b.selected = 1WHERE (' store_id ' = ' ten ') and (a.member_id in (' 7 ')) and ((B.province LIK E '% Sucheng District ') or (b.city like '% of Sucheng District% ') or (B.area like '% Sucheng District% ') or (B.detail like '% Sucheng District% ') "ORDER by addtime Desc, sendtime A SC, paytime desclimit 0,10
As you can see from the SQL statement, the parentheses in the where, the and,or combination is ingenious.
As follows
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "CodeIgniter Getting Started Tutorial", "CI ( CodeIgniter) Framework Advanced Tutorial, Zend Framework Introduction tutorial, Smarty Template Primer Basic Tutorial and PHP template technology summary.
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.