Page 1 of 1
search?
Posted: Wed Apr 30, 2003 6:36 am
by AndrewBacca
what i want to do is allow users of my site it search my database, using keyword(s) or phrases?
for example, if they type 'planets', then it will list any news/articles with the word 'planets' in it. and if they enter '"jupiters moons"' (with the "") it will find only the records with "jupiters moons" some where in it.
im not sure how to do this, so any help would be great
cheers
Andrew
Posted: Wed Apr 30, 2003 7:27 am
by twigletmac
If you are using MySQL you can use the LIKE keyword:
Code: Select all
SELECT field1, field2, field3 FROM table WHERE field1 LIKE '% keyword %'
http://www.mysql.com/doc/en/String_comp ... ml#IDX1216
Mac
Posted: Wed Apr 30, 2003 9:50 am
by AndrewBacca
cheers, ive got it working
Andrew
Posted: Wed Apr 30, 2003 3:19 pm
by McGruff
And to get "planet" but not "planetary"
RLIKE '[[:<:]]" . $value . "[[:>:]]'
Posted: Thu May 01, 2003 1:58 am
by twigletmac
McGruff wrote:And to get "planet" but not "planetary"
RLIKE '[[:<:]]" . $value . "[[:>:]]'
You can still use LIKE for that, as in the example I gave, just put spaces between the keyword and the wildcards (%).
Mac
Posted: Thu May 01, 2003 7:22 am
by McGruff
twigletmac wrote:McGruff wrote:And to get "planet" but not "planetary"
RLIKE '[[:<:]]" . $value . "[[:>:]]'
You can still use LIKE for that, as in the example I gave, just put spaces between the keyword and the wildcards (%).
Mac
Would that find planet in:
"... the red planet. New sentence ..etc.."
or
".. planet-forming .."
ie are non-alphabetic chars like punctuation or dashes treated as spaces?
Not trying to be a smartass - that's why I use RLIKE but maybe I don't need to.
Posted: Thu May 01, 2003 9:08 am
by twigletmac
Good point about punctuation, forgot about that...
I tend to do 'beginning of word' or 'part of word' searches so LIKE is fine but you're right McGruff, use RLIKE for 'this word only' searches.
I was just looking at the example given and not thinking further than that, sorry.
Mac