Thinkphp3.2 searches multiple fields in a table based on multiple keywords

describe the problem

A list of products that needs to be displayed according to different keywords. Keywords appear in "highlight_desc | keywords | page_title | description", respectively. Such as keywords "42L large capacity", "one-click menu".
I am now searching for a keyword that has data, but if combined, there is no data. The desired result of
is that as long as the keyword is in any field, the result is displayed.

Code

$goods = D("GoodsserialView");

$where = array("goods.cate"=>$cate, "goods.status"=>1);
            
$keywords = "%".$keys."%";
$where["highlight_desc|keywords|page_title|description"] = array("LIKE", $keywords);

  • it is recommended to use native SQL using MySQL's concat () method to separate the fields that need to be matched with specific characters and then use LIKE,
  • secondly, you need to note that if you use IFNULL to determine that the field is NULL, you will use an empty string instead, otherwise the whole connection will be NULL, because of one NULL, and the result will not be found.
  • if one of the fields has a lot of content, it's best to exclude that field and LIKE it with or.

write the native version directly with query


$where ['nickname | openid'] = array (' like','%'.$keyword.'%');

clipboard.png


clipboard.png

reference: http://document.thinkphp.cn/m.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3049c-2bd0b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3049c-2bd0b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?