You are here: search script problem « PHP SQL « IT news, forums, messages
search script problem

Posted by mbarbs on 08/27/07 23:54

I've written my first search script and I have 2 problems. First, I'm
getting duplicate results because I have identical questions related
to different topic_id's (aka categories). Second, if a search term
isn't found, it's
not displaying the "No search results" text on the last line. Any help
would be greatly appreciated.

<?php

$searchTerms = $_POST['search_term']; $searchSection =
$_POST['search_type'];

if($searchSection == 1) {

require_once 'db_connector.php';

$connector = new DB_Connector();

$result = $connector -> query("SELECT * FROM 1_questions WHERE
question LIKE '%$searchTerms%'");

echo '<span class="title">Search Results</span>';
echo '<div class="title_rule"></div>';

while($row = $connector -> fetchArray($result)) {

echo '<div class="question">'.$row['question'].'</div>';
echo nl2br('<div class="answer">'.$row['answer'].'</div>');
echo '<br />';

} }

elseif($searchSection == 2) {

require_once 'db_connector.php';

$connector = new DB_Connector();

$result = $connector -> query("SELECT * FROM 2_questions WHERE
question LIKE '%$searchTerms%'");

echo '<span class="title">Search Results</span>';
echo '<div class="title_rule"></div>';

while($row = $connector -> fetchArray($result)) {

echo '<div class="question">'.$row['question'].'</div>';
echo nl2br('<div class="answer">'.$row['answer'].'</div>');
echo '<br />';

} }

else{

exit('<span class="title">Search Results</span><div
class="title_rule"></div><div class="question">No search resluts
found.</div>'); }

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация