Re: help with mysql querry
| From: | Jay D. Mumper | Date: | Tue, 01 Aug 2000 19:16:13 +0000 |
| Subject: | Re: help with mysql querry | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9525@lists.php.net to get a copy of this message | ||
Kurth Bemis wrote:
>
> i am working on a home search engine for a company but have run into a
> stumbling block. i'd like to be able to say "no home returned" when there
> isn't a home that matches the querry in the table. i added
> mysql_num_rows() but i can't get it to work correctly. also...another
> quick question - i have 2 counters that tell the user how many homes were
> found and how many are on display.. if you look at my source you'll see
> that the code that displays it at the end of the loop. why is it displayed
> at the top of the page? i can't for the life of me figure it out.
I can tell you why the count is at the top - it is rendered *inside*
your table, but outside of any rows - just display it after the closing
</TABLE> tag and it will be at the bottom.
Put your mysql_num_rows() test _outside_ the fetch loop. If there
are no rows, spew the "no homes found" message, else display each
record.
One other "style" thing - try having only one mysql_query call after
you've set the value of the query string via your conditionals. It's
easier to trace down problems that way. For debugging, you can just
print the value of the query string at one place.
if (<some condition) {
$query = "SELECT * FROM blah, blah, blah...";
}
//...
// DEBUG print ("QUERY STRING: $query<BR>");
$result = mysql_query($query);
if (mysql_num_rows($result)) {
while($myrow = mysql_fetch_row($result)) {
// display stuff
}
}
else {
// display no homes found
}
Hope this helps...
--
Jay Mumper
Consultant / Anteil, Inc.
http://www.anteil.com