Hi there, I'm wondering if anyone could help me.
I'm having no end of trouble trying to make a search engine work on my test php site. I've tried creating the code myself (at the bottom) and I'm having some success, but little things elude me, as I will explain.
These are my search requirements:
I wish to search on one field in one table.
I'd like to be able to enter multiple keywords. eg 'word1' 'word2' at the same time
I wish to stop duplicate results.
Possibly filtering out noise words such as 'the' 'it' 'a' etc.
The article here on PHP Builder about creating search engines has helped me a lot, but it's not quite what I need and some bits are hard to understand as I am a fairly new user. I like the idea of filtering out noisewords but I just can't get it to work with my code.
Here is what I have so far:
include("config.inc.php");
$connection = @mysql_connect($host, $user, $pass)
or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
if ($query) { //Query is the value I inputted
$filtered = $query;
$eachword = explode(" ", $filtered); //Split the query up if more than one word
for ($k=0; $k < count($eachword); $k++) { For each split word do a check
$sql = "SELECT ticket_id, prob_desc FROM $table_logs WHERE prob_desc LIKE '%$eachword[$k]%'";
$result = @($sql,$connection) or die("Couldn't execute user query 4.");
while ($row = mysql_fetch_array($result)) {
$ticket_id = $row['ticket_id'];
$prob_desc = $row['prob_desc'];
if ($ticket_id != $check[$e]) {
$html_block .= "<tr><td>$ticket_id <td>$prob_desc";
}
$check[] = $ticket_id;
}
}
$bob = implode('<br> ', $check);
echo $bob;
}
?>
<body>
<form method=post action='<? $PHPSELF ?>'>
<input type=text name=query>
<input type=submit name=now value=now>
</form>
<table>
<? echo $html_block; ?>
</table>
My problem is that if my field has more than one of the Query words in it, the results will be displayed more than once, and i wish to filter this down so that only one of the same result is displayed.
I realise there must be an easy way but i just cant seem to get my head around it, which is why i'm fairly new to this. 🙂
What may be preferable to u lot is if you could provide me with a link to some sample code that does what i require in nice easy steps so that i can study it, rather than providing an answer to that mess of a code above 🙂
I hope u understood what i have been babbling on about.
Thanks in advance!