$ searchTitle,$ searchKeywords,$ searchCity,$ searchCountry,$ searchName,$检索类别
出现逗号时,“标题”字段的搜索词将分开:
$terms1 = preg_split("/[\s,-]+/", $searchTitle);
关键字字段:我还允许在关键字字段中使用逗号分隔的单词(最多3个单词)。
现在,当逗号出现时,关键字字段的搜索字词将被分开:
$terms2 = preg_split("/[\s,-]+/", $searchKeywords);
现在查询:
SELECT * FROM MyDataTable
WHERE Title LIKE '%$terms1[0]%'
AND Title LIKE '%$terms1[1]%'
AND Title LIKE '%$terms1[2]%'
AND Keywords LIKE '%$terms2[0]%'
AND Keywords LIKE '%$terms2[1]%'
AND Keywords LIKE '%$terms2[2]%'
AND City LIKE '%$searchCity%'
AND Country LIKE '%$searchCountry%'
AND Name LIKE '%$searchName%'
AND Type LIKE '%$searchType%'
order by UploadDate
问题:代码有效,但看起来很耐心,我不确定它是最聪明的查询方式。任何提示都会有所帮助。 干杯。