search script problem

search script problem

am 28.08.2007 01:54:17 von Matt Barbadian

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.


$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 'Search Results';
echo '

';

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

echo '
'.$row['question'].'
';
echo nl2br('
'.$row['answer'].'
');
echo '
';

} }

elseif($searchSection == 2) {

require_once 'db_connector.php';

$connector = new DB_Connector();

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

echo 'Search Results';
echo '
';

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

echo '
'.$row['question'].'
';
echo nl2br('
'.$row['answer'].'
');
echo '
';

} }

else{

exit('Search Results class="title_rule">
No search resluts
found.
'); }

?>

Re: search script problem

am 28.08.2007 11:35:08 von Captain Paralytic

On 28 Aug, 00:54, mbarbs wrote:
> 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.
>
> >
> $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 'Search Results';
> echo '

';
>
> while($row = $connector -> fetchArray($result)) {
>
> echo '
'.$row['question'].'
';
> echo nl2br('
'.$row['answer'].'
');
> echo '
';
>
> } }
>
> elseif($searchSection == 2) {
>
> require_once 'db_connector.php';
>
> $connector = new DB_Connector();
>
> $result = $connector -> query("SELECT * FROM 2_questions WHERE
> question LIKE '%$searchTerms%'");
>
> echo 'Search Results';
> echo '
';
>
> while($row = $connector -> fetchArray($result)) {
>
> echo '
'.$row['question'].'
';
> echo nl2br('
'.$row['answer'].'
');
> echo '
';
>
> } }
>
> else{
>
> exit('Search Results > class="title_rule">
No search resluts
> found.
'); }
>
> ?>

The way I read it, the "No search resluts (SIC) found" text is
triggered by the posted input value of search_type being something
other than 1 or 2. It has nothing to do with finding anything in the
searches themselves.

Re: search script problem

am 28.08.2007 19:34:35 von unknown

Post removed (X-No-Archive: yes)

Re: search script problem

am 09.09.2007 15:33:17 von Larry Anderson

for duplicate in the SQL query use DISTINCT