I developed a successful search function that works a treat. This used the FULLTEXT method.
Ive taken this further so now the user an choose between 4 sections to search i.e faq'.s jargon buster, general or quality systems. To establish the choice of which table to do a FULLTEXT search on I have this code:
(The choice depending on the choice made in the group of radio buttons)
include("connect.php");
$search = $_POST['search'];
////search choice is general
if ($search == "general") {$sql= "SELECT * FROM qualityquestsite WHERE MATCH (content) AGAINST ('" . stripslashes (str_replace (""", "\"", ($_POST['search']))) . "' IN BOOLEAN MODE)";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
// begin output here:
echo '
<TABLE BORDER=1 CELLPADDING=2>
<TR> <TH COLSPAN=2 BGCOLOR="#99CCFF"></TH> </TR>
<TR> <TD WIDTH=500><a href="' . $row['search_url'] . '">' . $row['search_title'] . '</a></TD> <TD WIDTH=250>' . $row['search_section'] .'</TD> </TR>
</TR>
</TABLE>';
}
}
}
else
////search choice is faq
if ($search == "faq") {$sql= "SELECT * FROM faq WHERE MATCH (question, explanation, category) AGAINST ('" . stripslashes (str_replace (""", "\"", ($_POST['search']))) . "' IN BOOLEAN MODE)";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
// begin output here:
echo '
<TABLE BORDER=1 CELLPADDING=2>
<TR> <TH COLSPAN=2 BGCOLOR="#99CCFF"></TH> </TR>
<TR> <TD WIDTH=500><a href="' . $row['search_url'] . '">' . $row['category'] . '</a></TD> <TD WIDTH=250>' . $row['search_section'] .'</TD> </TR>
</TR>
</TABLE>';
}
}
}
else
////search choice is jargon
if ($search == "jargon") {$sql= "SELECT * FROM jargon WHERE MATCH (jargonterm, explanation) AGAINST ('" . stripslashes (str_replace (""", "\"", ($_POST['search']))) . "' IN BOOLEAN MODE)";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
// begin output here:
echo '
<TABLE BORDER=1 CELLPADDING=2>
<TR> <TH COLSPAN=2 BGCOLOR="#99CCFF"></TH> </TR>
<TR> <TD WIDTH=500><a href="' . $row['search_url'] . '">' . $row['jargonterm'] . '</a></TD> <TD WIDTH=250>' . $row['search_section'] .'</TD> </TR>
</TR>
</TABLE>';
}
}
}
else
///search choice is qualitysystems
if ($search== "qualitysystem") {$sql= "SELECT * FROM qualityadmin WHERE MATCH (quality_name, local_agency, contact, what_is_it, who_what_apply, how_work, resource_implications, how_meet_standards, widespread, pros_cons, benefits) AGAINST ('" . stripslashes (str_replace (""", "\"", ($_POST['search']))) . "' IN BOOLEAN MODE)";
$result = mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
// begin output here:
echo '
<TABLE BORDER=1 CELLPADDING=2>
<TR> <TH COLSPAN=2 BGCOLOR="#99CCFF"></TH> </TR>
<TR> <TD WIDTH=500><a href="' . $row['search_url'] . '">' . $row['search_title'] . '</a></TD> <TD WIDTH=250>' . $row['search_section'] .'</TD> </TR>
</TR>
</TABLE>';
}
}
}
Now though Im getting zero results- nothing on the screen at all. I cannot see why this. Can anyone help?