Jump to content

Recommended Posts

Hi,

I have a search script running on my website but it does not support boolean operators.  I am finding that the results I am getting are very limited and many are being ignored as the words are not next to each other in the keyword row.

I have tried to follow a couple of tutorials I found on the net but have been unsuccessful in implementing them.  What I want is to be able to search through the keywords row in my database using boolean operators and display the results as my current search does, but in order of relevance.

I would really appreciate some help with this as I am not having any success.

Here is my search form:

[code]<form name="search" method="post" action="srch.php">
<input class="form3" type="text" name="find" maxlength="255" />
<input style="vertical-align: top;" class="submit" type="submit" name="search" value="Go" />
<input type="hidden" name="searching" value="yes" />
</form>[/code]


Here is my search processing / results page

[code]<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "USER", "PASS") or die(mysql_error());
mysql_select_db("pagelinks") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM links WHERE keywords LIKE '%$find%'");

$num_per_page=10;

$num=mysql_num_rows($data);

$num_pages=ceil($num/$num_per_page);

$pages=Array();

for ($i=0;$i<$num_pages;$i++)
$pages[]="<a href=\"?searching=yes&find=$find&start=".$i."\">[".($i+1)."] </a>";

$pages=implode("&nbsp;",$pages); #Here's your string with the page links, output where ever

if ($start<0)
$start=0;

$x=($start*$num_per_page);
$y=$num_per_page;

$query="SELECT * FROM links WHERE keywords LIKE '%{$find}%' LIMIT {$x},{$y}";
$data = mysql_query($query);

//And we display the results
while($result = mysql_fetch_array( $data ))
{

echo "<hr /><br />";
if ($result['new_window'] == 1) {
echo "<b><a href=\"".$result['url']."\" target=\"_new\">".$result['link_text']."</a></b>";
} else {
echo "<b><a href=\"".$result['url']."\">".$result['link_text']."</a></b>";
}
echo "<br />";
echo $result['description'];
echo "<br />";
if ($result['new_window'] == 1) {
echo "<a href=\"".$result['url']."\" target=\"_new\">".$result['url']."</a>";
} else {
echo "<a href=\"".$result['url']."\">".$result['url']."</a>";
}
echo "<br /><br />";
}

echo "<hr /><br />";

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}

echo "<br /><br />";
echo $pages;
?>[/code]


Thanks,

John
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.