Jump to content

Archived

This topic is now archived and is closed to further replies.

feri_soft

Keyword search

Recommended Posts

How to create a keywords search which can search 1 in the title, 2 in the description.

Please help,desperately need a solution.  :-\

Share this post


Link to post
Share on other sites
SELECT * FROM tablename
WHERE (title LIKE '%$keyword%')
OR (description LIKE '%$keyword%')

Share this post


Link to post
Share on other sites
To do Google-like searching ("bla3 bla1" -bla2 +bla3) you may use fulltext searching: [code]SELECT * FROM tablename WHERE MATCH (title,body) AGAINST ('"bla3 bla1" -bla2 +bla3' IN BOOLEAN MODE);[/code]

Share this post


Link to post
Share on other sites
Bernard are you sure that SELECT * FROM tablename
WHERE (title LIKE '%$keyword%')
OR (description LIKE '%$keyword%') will find exactly the matches...because i dont want unneeded results.

Share this post


Link to post
Share on other sites
To find exact matches, remove the percentage signs:
[code]

<?php

SELECT * FROM tablename WHERE (title LIKE '$keyword') OR (description LIKE '$keyword') // exact match

SELECT * FROM tablename WHERE (title LIKE '%$keyword%') OR (description LIKE '%$keyword%') // match somewhere in

SELECT * FROM tablename WHERE (title LIKE '$keyword%') OR (description LIKE '$keyword%') // exact match on "starting with"

SELECT * FROM tablename WHERE (title LIKE '%$keyword') OR (description LIKE '%$keyword') // exact match on "ending with"

?>

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.