$word) { if (isset($stop_words[strtolower($word)])) { $words_removed[] = $word; unset($words[$index]); } } } // generate HTML form ob_start(); ?>
$word) { if (!pspell_check($ps, $word)) { if ($s = pspell_suggest($ps, $word)) { if (strtolower($s[0]) != strtolower($word)) { // (ignore capitalization-related spelling errors) $spell_error = true; $suggest_words[$index] = $s[0]; } } } } // formulate the search query using provided terms and submit it $join = ''; $where = ''; $query = 'SELECT DISTINCT D.DOCUMENT_URL, D.DOCUMENT_TITLE, ' . 'D.DESCRIPTION FROM WROX_SEARCH_DOCUMENT D '; foreach ($words as $index => $word) { $join .= sprintf( 'JOIN WROX_SEARCH_INDEX I%d ON D.DOCUMENT_ID = I%d.DOCUMENT_ID ' . 'JOIN WROX_SEARCH_TERM T%d ON I%d.TERM_ID = T%d.TERM_ID ', $index, $index, $index, $index, $index); $where .= sprintf('T%d.TERM_VALUE = "%s" AND ', $index, mysql_real_escape_string(strtolower($word), $GLOBALS['DB'])); } $query .= $join . 'WHERE ' . $where; // trimmed 4 characters o remove trailing ' AND' $query = substr($query, 0, strlen($query) - 4); $result = mysql_query($query, $GLOBALS['DB']); // display results echo '
'; $num_rows = mysql_num_rows($result); echo '

Search for ' . htmlspecialchars(join(' ', $words)) . ' yielded ' . $num_rows . ' result' . (($num_rows != 1) ? 's' : '') . ':

'; // show suggested query if a possible misspelling was found if ($spell_error) { foreach ($words as $index => $word) { if (isset($suggest_words[$index])) { $words[$index] = $suggest_words[$index]; } } echo '

Possible misspelling. Did you mean ' . htmlspecialchars(join(' ', $words)) . '?

'; } echo ''; } $GLOBALS['TEMPLATE']['content'] = ob_get_clean(); // display the page include '../templates/template-page.php'; ?>