English 中文(简体)
改进搜索工具
原标题:improve search formular

我想作一个搜索稿,我可以在这里寻求多字,但文字却在所有各行中找到,而不是一个特定的行文。 例如。

  __________________________   ________
 |Cheese                    | | Search |
  ——————————————————————————   ————————

接着,我发表了一份介绍:

SELECT * FROM table WHERE column1 = "$value" OR column2 = "$value" OR column3 = "$value" ... ;

这将显示“车臣”一词出现在任何一栏中的结果。 事情是,我希望人们能够寻求“友好”和“礼让”,但我需要把言词分开,寻找这样的东西:

SELECT * FROM table WHERE column1 = "$value" OR column2 = "$value" OR column3 = "$value" ... AND column1 = "$value2" OR column2 = "$value2" OR column3 = "$value2" ... ;

The thing is that I really don t know how to do this. neither the word separation or how to find the words i the SQL database.. Also I don t know how to search for the words where "Cheese" is a part of.. like "Cheesecake"..

如果有人想如何做到这一点,请帮助我。

谢谢。

问题回答

你们的所有需要都是正确的家长:

SELECT *
FROM table
WHERE (column1 = "$value" OR column2 = "$value" OR column3 = "$value") AND
      (column1 = "$value2" OR column2 = "$value2" OR column3 = "$value2")

"AND"s get evaluated before "OR"s.

因此,不得不通过多个栏目进行查询,表明您的数据模型可能出现短缺。 你可能希望有一个表格结构,将每个字放在一个单独的行文中。

不可能用一个条款搜索一整段。 但是,你可以使用LKE条款来寻找像“Cheese”这样的词语,并且与“Cheesecake”相匹配。

This is going to get a lot more complicated than you think. I suggest looking into something like MySQL s MyISAM s full text searching, or if you plan on doing frequent searches or on large sets of data using something like Sphinx. Also, if you do decide to follow your current route, what you re looking for is a LIKE clause.

不管怎样,寻找含有che或ake的言词:

SELECT blah FROM tbl WHERE (col1 LIKE  %cheese%  OR col2 LIKE  %cheese% ) AND (col1 LIKE  cake  OR col2 LIKE  cake );

This is extremely inefficient though. It can t use indexes, meaning it will require a full table scan for every query.

你对这些询问进行了良好的跟踪。

最明显的情况是,你在Kall的野心操作员。 这与部分扼杀相匹配。 例如,这将发现“che”和“che”记录:

SELECT *
FROM table
WHERE column1 =  %cheese% 

More advanced ways of handling searches involve indexing the data you want to search. Either doing it yourself or using third party or specific database tools. Look this up in Google.

然而,对于一个经常点,没有受到许多搜查的打击,你目前的做法是罚款的。

还有一点:如果你问,如何在搜索箱中自动增加每个字的外线,你需要学习更多的东西。 开始在正式的PHP文件(php.net)中研究这些术语,

  • explode
  • foreach

Why not retrieve all the data you need and use string function to campare the searched item from the haystack, i believe stristr would be of help to you, or you can just use SQL Query but then that might be stressful for your DB. correct me if im wrong.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签