Reputation: 38
I need a powerful search code for my product databse
In That I need to search keywords that present in product title and description
when we type a word it should list the word and next words following that word in the sentence.
Can Anybody help with the below code
$sql="SELECT REPEAT (pr_name,1) AS names, REPEAT (pr_description, 1) AS pdes, REPEAT ('pr',1) AS lity FROM products WHERE pr_name like '%".$searchq."%' OR pr_description like '%".$searchq."%'".$qrtxt1." UNION SELECT REPEAT (sr_title, 1) AS names, REPEAT (sr_description, 1) AS pdes, REPEAT ('ser',1) AS lity FROM services WHERE sr_title like '%".$searchq."%' OR sr_description like '%".$searchq."%'".$qrtxt2." ORDER BY names LIMIT 10";
$result = mysql_query($sql);
echo "<ul class='livelist'>";
while($row = mysql_fetch_array($result))
{
$restext1='';
$restext2='';
$restext1= magicWords($searchq, $row['names']);
$restext2= magicWords($searchq, $row['pdes']);
if(!empty($restext1))
{
$wrappedtext1=wordwrap($restext1);
echo "<li id=".$row['lity']." onclick='clearlist(this.innerHTML,this.id)'>".substr($wrappedtext1, 0, strpos($wrappedtext1, "\n"))."<li>";
}
if(!empty($restext2))
{
$wrappedtext2=wordwrap($restext2);
echo "<li id=".$row['lity']." onclick='clearlist(this.innerHTML,this.id)'>".substr($wrappedtext2, 0, strpos($wrappedtext2, "\n"))."<li>";
}
}
echo "</ul>";
Upvotes: 1
Views: 6698
Reputation: 4506
Try this tutorial, you can get an idea to implement Auto suggest option as you want. There Sample code and demo available. You can develop Auto suggest task using this. http://coding.pressbin.com/19/Implementing-Google-auto-suggest-using-jQuery
Demo: http://www.pressbin.com/
Upvotes: 1