Hi,
I have created a knowledge base filled with articles which I am using the FULLTEXT function in mysql to search. The search works perfectly and gives me the required results, but I would like that if more than 10 results returned, give option to next page. Here is what I have:
CODE:
<?php
// Create the search function:
function searchForm()
{
// Re-usable form
// variable setup for the form.
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
$normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
$boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );
echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="cmd" value="search" />';
echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';
echo 'Mode: ';
echo '<select name="mode">';
echo '<option value="normal"'.$normal.'>Normal</option>';
echo '<option value="boolean"'.$boolean.'>Boolean</option>';
echo '</select> ';
echo '<input type="submit" value="Search" />';
echo '</form>';
}
// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');
switch($cmd)
{
default:
echo '<h1>Search Database!</h1>';
searchForm();
break;
case "search":
searchForm();
// echo '<h3>Search Results:</h3><br />';
$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT * FROM KB_TEST
WHERE MATCH (Problem, ArticleTitle, Cause, Symptom)
AGAINST ('$searchstring' IN BOOLEAN MODE)";
break;
case "boolean":
$sql = "SELECT * FROM KB_TEST
WHERE MATCH (Problem, ArticleTitle, Cause, Symptom)
AGAINST ('$searchstring' IN BOOLEAN MODE)";
break;
}
// echo $sql;
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_object($result))
{ ?>
<font size="2" face="Tahoma"><strong><a href=" echo ($row->KBID); ?>"><?php echo ($row->Problem); ?> </a></strong></font><br>
<font size="1" face="Tahoma">
<?php
echo 'Article:'.stripslashes(htmlspecialchars($row->ArticleTitle));
echo '<br>'.stripslashes(htmlspecialchars($row->Cause));
echo '<hr size="1" />';
}
break;
}
?>
/CODE
Any help is appreciated.
Thanks,
dr
I have created a knowledge base filled with articles which I am using the FULLTEXT function in mysql to search. The search works perfectly and gives me the required results, but I would like that if more than 10 results returned, give option to next page. Here is what I have:
CODE:
<?php
// Create the search function:
function searchForm()
{
// Re-usable form
// variable setup for the form.
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
$normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
$boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );
echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="cmd" value="search" />';
echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';
echo 'Mode: ';
echo '<select name="mode">';
echo '<option value="normal"'.$normal.'>Normal</option>';
echo '<option value="boolean"'.$boolean.'>Boolean</option>';
echo '</select> ';
echo '<input type="submit" value="Search" />';
echo '</form>';
}
// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');
switch($cmd)
{
default:
echo '<h1>Search Database!</h1>';
searchForm();
break;
case "search":
searchForm();
// echo '<h3>Search Results:</h3><br />';
$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT * FROM KB_TEST
WHERE MATCH (Problem, ArticleTitle, Cause, Symptom)
AGAINST ('$searchstring' IN BOOLEAN MODE)";
break;
case "boolean":
$sql = "SELECT * FROM KB_TEST
WHERE MATCH (Problem, ArticleTitle, Cause, Symptom)
AGAINST ('$searchstring' IN BOOLEAN MODE)";
break;
}
// echo $sql;
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_object($result))
{ ?>
<font size="2" face="Tahoma"><strong><a href=" echo ($row->KBID); ?>"><?php echo ($row->Problem); ?> </a></strong></font><br>
<font size="1" face="Tahoma">
<?php
echo 'Article:'.stripslashes(htmlspecialchars($row->ArticleTitle));
echo '<br>'.stripslashes(htmlspecialchars($row->Cause));
echo '<hr size="1" />';
}
break;
}
?>
/CODE
Any help is appreciated.
Thanks,
dr