Hey, I can't figure out how to do something. I have a script that searches a table and returns each entry that contains one or more of the keywords. The problem is that it shows the same result for each keyword that shows up. I want each entry to only show up once. I'm not sure what the best way to do this is. Also, is there any way to sort the results depending on how many keywords show up in an entry?
Here's the script I have so far:
PHP Code:
<?php
include("config.php");
include("layout_header.php");
echo "<table class=\"table\" cellspacing=\"0\"><tr class=\"title\"><td>Search</td></tr>\n";
echo "<tr class=\"content\"><td>\n";
if(!$_GET['keywords']){
echo "<form action=\"$PHP_SELF\" method=\"get\">\n";
echo "<input type=\"text\" name=\"keywords\">\n";
echo "<input type=\"submit\">\n";
echo "</form>\n";
}else{
$keywords_array = explode(" ",$_GET['keywords']);
foreach($keywords_array as $keyword){
$query = mysql_query("SELECT * FROM `hlcd_clans` WHERE `name` OR `description` LIKE '%$keyword%'");
if(mysql_numrows($query) < 1){
echo "Your search returned no results. <a href=\"$PHP_SELF\">Back</a>\n";
}
while($myrow = mysql_fetch_array($query)){
$id = $myrow['id'];
$name = $myrow['name'];
$description = $myrow['description'];
echo "<a href=\"listing.php?id=$id\">$name</a><br>$description<br><br>\n";
}
}
}
echo "</td></tr></table>\n";
include("layout_footer.php");
?>
Any help would be appreciated.