[thelist] quick php/mysql search engine question

Howard Cheng howcheng at ix.netcom.com
Thu Sep 12 13:39:01 CDT 2002


"SELECT * FROM $table WHERE keyword LIKE '%$keyword%'"

Of course, this also creates a problem where if your keyword contains
entirely the word you're searching for, it will also turn up. For example,
if your keyword is "discontinued" and someone searches for "con" you will
still get this record.

You may want to normalize your tables a little more, by creating another
table that links your data to its keywords:

TABLE 1
id    name
-----------
1     xxx
2     yyy
3     zzz

KEYWORD TABLE
id    thing_id   keyword
------------------------
1     1          bird
2     1          flight
3     1          feather
4     2          something
5     2          something else
6     2          motor

etc.

That way you just join the tables together in your query and you don't have
to use the LIKE clause.

HTH.


At 06:11 PM 9/12/2002 +0000, Dunstan Orchard wrote:
>"SELECT * FROM $table WHERE keyword LIKE '$keyword%'"

::::::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/ <-- NEW!
howcheng at ix dot netcom dot com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list