Suggestion Box for related keywords for my website

Hi,

I am trying to create a suggestion box for my website…which should must show keywords suggestions like this…

So if I am searching a single word or a full string it should show all the related keywords as given above.

I hope I’ve explained enough to get my point.

If there’s something unclear please let me know.

Thanks in Advance.

I am looking for the relevant keywords with the LIMIT of 50 only.

I’ve put an example above…so please let me know there any way to get the relevant results…as this one is not good for me.

Thanks for your help though.

Thanks Anthony,

I will try this and let you know the out put.

Thanks a lot.

This will build the SQL query for you with an unlimited amount of keywords.


<?php
$sql = 'SELECT * FROM category WHERE 1 <> 1';
foreach(preg_split('/([\\s&-]+)/', $_POST['keywords']) as $keyword){
    if(0 < strlen($keyword)){
        $sql .= sprintf(
            " OR category LIKE '&#37;%%s%%'",
            mysql_real_escape_string($keyword)
        );
    }
}
?>

Well its here:

I am new so there may be silly mistakes…:slight_smile:


$pieces = preg_split('/[\\s&-]+/',$keyname);
					$break = count($pieces);
					if ($break==5)
					$sql_category="select * from category where category like '$keyname&#37;' or category like '$pieces[0] $pieces[1]%' or category like '$pieces[2]%' or category like '$pieces[3]%' or category like '$pieces[4]%' order by category LIMIT 50";
					if ($break==4)
					$sql_category="select * from categorywhere category like '$keyname%' or category like '$pieces[0] $pieces[1]%' or category like '$pieces[2]%' or category like '$pieces[3]%' order by category LIMIT 50";
					if ($break==3)
					$sql_category="select * from category where category like '$keyname%' or category like '$pieces[0] $pieces[1]%' or category like '$pieces[2]%' order by category LIMIT 50";
					if ($break==2)
					$sql_category="select * from category where category like '$keyname%' or category like '$pieces[0] $pieces[1]%' order by category LIMIT 50";
					else
					$sql_category="select * from category where category like '$keyname%' or category like '$pieces[0]%' order by category desc LIMIT 50";


Any expert comments would be appreciated.

Thanks

To add a limit, you simply add, well, a limit. :smiley:


<?php
$sql = 'SELECT * FROM category WHERE 1 <> 1';
foreach(preg_split('/([\\s&-]+)/', $_POST['keywords']) as $keyword){
    if(0 < strlen($keyword)){
        $sql .= sprintf(
            " OR category LIKE '&#37;%%s%%'",
            mysql_real_escape_string($keyword)
        );
    }
}
$sql .= ' LIMIT 50';
?>

What code do you have so far?