Forums

PHP

This topic is locked

help with a query

Posted 07 Nov 2001 05:20:41
1
has voted
07 Nov 2001 05:20:41 Michael Davis posted:
Using MYSQL/PHP/UD with PhaKt, but I'm definetly a newbie.
I have a database field with the following term:
"lead-based paint"

I'm trying to run a query that will return a result.
The query is :

SELECT * FROM database WHERE term LIKE '%MMColParam%'
If I type in "lead" I get result. With "lead paint", no result.
I find if I type "lead%paint", I get results.

Is therea way to convert the spaces in a search from my form to "%" for wildcard?


Replies

Replied 07 Nov 2001 14:07:47
07 Nov 2001 14:07:47 Bruno Mairlot replied:
Yes you should the FullText feature of MySQL which is exactly what you're looking for.

In short :

1. Create a fulltext index on the fields you're looking on : "ALTER TABLE tableName ADD fulltext(fieldName1,fieldName2,...)"
2. Your query changes in :
"SELECT * from tableNAme WHERE MATCH (fieldName1,fieldName2,..) AGAINST ('lead')"

Of course change tableName,fieldNameXX with your configuration.

In long :
www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Fulltext_Search

Bruno

--- Better to die trying, than never try at all ---
Replied 07 Nov 2001 15:54:56
07 Nov 2001 15:54:56 Michael Davis replied:
Thanks for the help, this looks like what I need. One problem, I get the following error. Do I have a syntax error?
table:chrarchive
fieldname:headline

Error
SQL-query:

ALTER TABLE chrarchive ADD FULLTEXT headline
MySQL said: You have an error in your SQL syntax near 'headline' at line 1



Replied 07 Nov 2001 16:00:53
07 Nov 2001 16:00:53 Bruno Mairlot replied:
Yes, when creating an index (any type) you need to enclose the fields you want to use into ( ). So your query is :

ALTER TABLE chrarchive ADD FULLTEXT<font color=red><b>(</b></font id=red>headline<font color=red><b></b></font id=red>





--- Better to die trying, than never try at all ---

Edited by - Maehdros on 11/07/2001 16:01:45

Reply to this topic