Page 1 of 1

[solved] Tag based search does not scan multiple tags

Posted: Wed Aug 20, 2008 1:22 pm
by Sindarin

Code: Select all

$db_select = "SELECT * FROM news WHERE news_tags='$tags' ORDER BY news.news_id ASC";
This returns the entries that their news_tags row is equal to $tags variable. However if I search for "test" and the row's value is e.g. "test testing tech", it doesn't get listed.

Re: Tag based search does not scan multiple tags

Posted: Wed Aug 20, 2008 2:12 pm
by Christopher
Use LIKE and the % wildcard character:

Code: Select all

// begins with
$db_select = "SELECT * FROM news WHERE news_tags LIKE '$tags%' ORDER BY news.news_id ASC";
// ends with
$db_select = "SELECT * FROM news WHERE news_tags LIKE '%$tags' ORDER BY news.news_id ASC";
// contains
$db_select = "SELECT * FROM news WHERE news_tags LIKE '%$tags%' ORDER BY news.news_id ASC";

Re: Tag based search does not scan multiple tags

Posted: Wed Aug 20, 2008 2:18 pm
by Sindarin
It works perfectly, thanks!