Comma separated values

Hi,
in my db I have fields

values, url, keywords

and keywords field have comma separated values entered by user.
In my live search script only first value from this keyword field is considered as a value.
here is the code


$query = $db->query("SELECT value, url, keywords FROM my_DB WHERE keywords LIKE '$queryString%' LIMIT 10");
if($query) {
while ($result = $query ->fetch_object()) {
$strUTF = iconv('cp1250','UTF-8',$result->value); 
echo '<a  class="bodyText" href="'.$result->url.'"><li onClick="fill(\\''.$strUTF.'\\');">'.$strUTF.'</a></font></li>'; 
}
}

how to iterate trough each keword field to be considered by script not just first one.

Regards,

Store each keyword in its own row in a separate table. Database fields should always be atomic (single valued).

Try:

$sql = "SELECT value, url, keywords FROM my_DB WHERE (keywords LIKE '$queryString&#37;' ) OR (value LIKE  '$queryString%') OR ( url LIKE  '$queryString%' )  LIMIT 10";

Put % in both side of your keyword:


SELECT value, url, keywords FROM my_DB WHERE keywords LIKE '%keyword%' LIMIT 10

Edit:
Or you can do something like this to search more words in the searched keyword:


$keywords = "test test1 test2 test3";
$words = explode(" ", $keywords);
$sql = "SELECT value, url, keywords FROM my_DB WHERE 1 ";
if(count($words) >= 1){
    $sql = $sql . " AND (keywords LIKE '%" . implode("%' OR keywords LIKE '%", $words) . "%')";
}
echo $sql;

thanks for your posts and your time.
I used the rajug advice and put % sign in both side of my $keyword var. Everything work just fine.

regards

This would be a better way to do it.