search script problem
4 Message(s) by 4 Author(s) originally posted in php sql
| From: mbarbs |
Date: Monday, August 27, 2007
|
I have 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
is not 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>'); }
?>
| From: Captain Paralytic |
Date: Tuesday, August 28, 2007
|
wrote in message:
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
is not 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>'); }
?>
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 hasn'thing to do with finding anything in the
searches themselves.
| From: Tom |
Date: Tuesday, August 28, 2007
|
wrote in message...
wrote in message:
I have 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
is not found, it's
not displaying the "No search results" text on the last line. Any help
'd 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>'); }
?>
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 hasn'thing to do with finding anything in the
searches themselves.
Depending which Database you are using, such as MySQL or PostreSQL, there's
usually some PHP
function s you can find at
http://www.php.net, that'd help
you get a count on your query results. As an example PosgreSQL'd use the
"pg_num_rows()" function whereas MySQL'd usually use "mysql_num_rows()".
Tom
--
NewsGuy Takes
Usenet Cellular!
Download
newsgroup MP3's to your Cell or PDA
Free Trial -
http://newsguy.com/cell phone.htm
| From: larry |
Date: Sunday, September 09, 2007
|
for duplicate in the
SQL query use DISTINCT
Next Message: MAXIMUM LENGTH OF LONGTEXT FIELD
Blogs related to search script problem
I have an apache server and I am using preprossessed webpages ...
Hi, I’m having
problem with an “MSN invite
script”. In local works great but on another site I get an error anyone can help? fix the error. smokestack, don’t know how.. pastebin the code. Would you like to log in as foo — foo in this
...
Search for a Good Webhosting Company
I have a small
problem. I intend to learn
PHP. I just wrote a small
script and I saved it in a file that I uploaded it on the server. Whenever I load it, instead of getting the expected result, the page simply lists the code of the
...
Java Script / AJAX :: RE: AJAX PHP problem
alert('name='+name+'\n\ncapacity='+capacity+'\n\nequipid'+equipid+'\n\nsave='+save); new Ajax.Request("trialsubmit.
php", { method: "post", postBody: 'desc='+name+'&capacity='+capacity+'&id='+equipid+'&save='+save, onComplete: show(id)
...
Java Script / AJAX :: RE: AJAX PHP problem
var capacity = $("capacity"+id).value; var equipid = $("equip"+id).value; var params = 'desc='+name+'&capacity='+capacity+'&id='+equipid; xmlHttp.onreadystatechange=stateChanged(id); xmlHttp.open("POST","trialsubmit.
php",true);
...
PHP Input validation
I was wondering if
PHP can read a file take the numbers in the file and check to see if the hidden input and the file are the same, if they are then allow the rest of the
script to check * or to let the user upload files,
...
Script error with google talk !
first
problem is with google talk -
script error when ever i open de programme.tried uninstalling and re installing it..no use.i am not able to close the error window and cant use g talk. 2nd
problem is with yahoo messenger-i am not able
...