Re: php/mySQL search/mysql_num_rows() error
- From: "Chris" <designerNOSPAM@xxxxxxxxxxxxxx>
- Date: Mon, 12 Jun 2006 14:53:07 -0700
Thanks,
The page will show, and I can get a result. However I now have other issues
with it. Apparently others have some of the same issues, such as duplicate
results, so I'm checking out those solutions around the Net. This search
code has apparently been available for quite a while, so may be based on an
earlier version of PHP. Also, it doesn't seem to have anything in the code
to make the results appear as a link (i.e. <a href>, etc.) so will have to
figure out where that goes.
Anyway, now I get an error in the search text box where the search
keyword(s) are supposed to be after you run the search. It says:
br /><b>Notice</b>: Undefined variable: q in
<b>c:\Inetpub\wwwroot\search.php</b> on line <b>85</b><br />
I thought it had to do with making it a 'sticky form', so the keyword will
stay in the box, but that perhaps this code was written when global
variables were on by default. The only place where the code refers to a $q
variable is in the form, and they also name the text box 'q'.
<form action="search.php" method="get" name="search">
<div align="center">
<input name="q" type="text" value=" <?php echo $q; ?> " size="15">
<input name="search" type="submit" value="Search">
</div>
</form>
So I tried to make it a sticky form using:
<input name="q" type="text" value=" <?php if (isset($_POST['q'])) echo
$_POST['q']; ?> " size="15">
But got the same error. Any thoughts on this?
Thaks
"J.O. Aho" <user@xxxxxxxxxxx> wrote in message
news:4f5ufoF1hfn4dU1@xxxxxxxxxxxxxxxxx
I suggest you do a small change to your code
//SQL queries uses single quotes to enclose strings
$query = "SELECT * FROM links WHERE pageURL LIKE '%$trimm%' OR
pageDesc LIKE '%$trimm%' OR pageTitle LIKE '%$trimm%' ORDER BY pageLink
DESC" ;
// Execute the query to get number of rows that contain search keywords
$numresults = mysql_query($query);
if($numresults) {
//$numresults is a resource!!!
$row_num_links_main = mysql_num_rows($numresults);
} else {
//$numresults is false
echo "Query: $query<br>\n".mysql_errno().":
".mysql_error()."<br>\n";
exit;
}
This way you see what is wrong with your query or if you have connection
problems. When the page is finished, you may want to store this in a error
log file instead of outputting it to the web page.
//Aho
.
- Follow-Ups:
- Re: php/mySQL search/mysql_num_rows() error
- From: J.O. Aho
- Re: php/mySQL search/mysql_num_rows() error
- References:
- php/mySQL search/mysql_num_rows() error
- From: Chris
- Re: php/mySQL search/mysql_num_rows() error
- From: J.O. Aho
- php/mySQL search/mysql_num_rows() error
- Prev by Date: Re: php/mySQL search/mysql_num_rows() error
- Next by Date: Seeking a PHP Person to Assist With my Website
- Previous by thread: Re: php/mySQL search/mysql_num_rows() error
- Next by thread: Re: php/mySQL search/mysql_num_rows() error
- Index(es):