Hi all
I am creating a smallish keyword search for a site I work on.
While the search works great for a single keyword search, it doesnt seem to like to search for multiple keywords.
The information the search is based on is a description field, that is just pure text.
Below is the code I am using - it does seem to want to loop the search, can anyone point out what I am doing wrong?
// text search only
$search2 = $search; // ignore this
$split_search = explode(" ",$search);
for($i = 0; $i < count($split_search); $i++)
{
if (empty($offset)) {
$offset=0;
}
$limit=10; // rows to return
$sql_search2 = "SELECT * FROM information WHERE (description LIKE '%$split_search[$i]%') ORDER BY name ASC";
$sql_search_total = mysql_query($sql_search2, $connection) or die("Could not execute query??.<br>");
$numrows = mysql_numrows($sql_search_total);
$sql_search = "SELECT * FROM information WHERE description LIKE '%$split_search[$i]%' ORDER BY name ASC limit $offset, $limit";
$result = mysql_query($sql_search, $connection) or die("Could not execute query??.");
echo "<FONT FACE=\"Verdana, Helvetica, Arial\" SIZE=\"-2\">
<b>Search results</b>: <i>$numrows</i> | <b>Search Word</b>: <i>$search</i><P>";
while ($row = mysql_fetch_array($result)){
$name = $row["name"];
$url = $row["url"];
$description = $row["description"];
echo "<FONT FACE=\"Verdana, Helvetica, Arial\" SIZE=\"-2\"><b><a href=\"$url\" target=\"new\">$name</a></b><br>";
echo "$description<p>";
} // end of while statement
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
$counter;
if ($newoffset == $offset) {
print "<FONT FACE=\"Verdana, Helvetica, Arial\" SIZE=\"-2\"><b>$i</b></font>\n"; }
else {
print "<FONT FACE=\"Verdana, Helvetica, Arial\" SIZE=\"-2\"><a href=\"$PHP_SELF?search=$search2&offset=$newoffset\">$i</a>\n";
}
}
}