简体   繁体   English

PHP MYSQL搜索关键字

[英]PHP MYSQL search keywords

I have a input field that search's for keywords in my database. 我有一个输入字段,用于搜索我的数据库中的关键字。 Say the title of a car listing is "Toyota surf 1990 SSR-X", I want to be able to search something like "Toyota 1990", how can I achieve this?. 说汽车列表的标题是“丰田冲浪1990 SSR-X”,我希望能够搜索“丰田1990”这样的东西,我怎样才能实现这一目标? If I search "Toyota surf" or "surf 1990" it works. 如果我搜索“丰田冲浪”或“冲浪1990”它是有效的。

$query = "SELECT * FROM cars WHERE title LIKE '%" . $search_keywords . "%'";

$query = "SELECT * FROM cars WHERE title LIKE '%" . $ query =“SELECT * FROM cars WHERE title LIKE'%”。 $search_keywords . $ search_keywords。 "%'"; “%'”;

That code used in MySQL, so it doesn't have any relates with the main PHP coding. 该代码在MySQL中使用,因此它与主要的PHP编码没有任何关系。

Try using the preg_match feature instead. 请尝试使用preg_match功能。 Here is an example: 这是一个例子:

preg_match("KEYWORDS", $variable)

And you could add an if statement. 你可以添加一个if语句。 Like the following: 如下:

if(preg_match("KEYWORDS", $variable))

I wish I could give you the solution that you are requesting for. 我希望我能为您提供您要求的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM