Specifications

FIGURE 26.7
Setting keywords for a story.
The search form in search_form.php contains a single field for keywords, and submits to
search.php, which queries the database of live stories to find matching content. The source for
search.php is shown in Listing 26.9.
LISTING 26.9 search.php Finds Matching Stories and Calculates a Percentage Match
Score
<?
include (“include_fns.php”);
include (“header.php”);
$conn = db_connect();
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].”’ “;
else
$k_string .= “k.keyword = ‘“.$k[$i].”’ “;
Building Practical PHP and MySQL Projects
P
ART V
612
32 7842 ch26 3/6/01 3:36 PM Page 612