Specifications

}
$and .= “and ($k_string) “;
}
$sql = “select s.id,
s.headline,
10 * sum(k.weight) / $num_keywords as score
from stories s, keywords k
where s.id = k.story
$and
group by s.id, s.headline
order by score desc, s.id desc”;
$result = mysql_query($sql, $conn);
echo “<H2>Search results</H2>”;
if (mysql_num_rows($result)) {
echo “<TABLE>”;
while ($qry = mysql_fetch_array($result)) {
echo “<TR><TD>”;
echo $qry[headline];
echo “</TD><TD>”;
echo floor($qry[score]).”%”;
echo “</TD></TR>”;
}
echo “</TABLE>”;
}
else {
echo “No matching stories found”;
}”);
include (“footer.php”);
?>
First, the keyword string passed into the script is split up into individual search words. We are
not using any advanced search techniques in this example, such as allowing the searcher to use
AND or OR keywords or group words together into a phrase.
if ($keyword) {
$k = split(“ “, $keyword);
$num_keywords = count($k);
for ($i=0; $i<$num_keywords; $i++) {
if ($i)
$k_string .= “or k.keyword = ‘“.$k[$i].”’ “;
Building a Content Management System
C
HAPTER 26
26
CONTENT
MANAGEMENT
SYSTEMS
613
LISTING 26.9 Continued
32 7842 ch26 3/6/01 3:36 PM Page 613