RE: [PHP] while loop with if statement - here's the code
| From: | Alnisa Allgood | Date: | Mon, 20 Aug 2001 15:35:40 +0000 |
| Subject: | RE: [PHP] while loop with if statement - here's the code | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-63528@lists.php.net to get a copy of this message | ||
At 11:02 AM -0400 8/20/01, sgibbs@vt.globalhealth.org wrote:
<? $results = mysql_db_query("$db", "select * from $table where $query order by update_datetime desc limit $offset, 10"); while($one = mysql_fetch_array($results)){ $id=$one["id"]; $title=$one["title"]; $description=$one["description"]; print " <TR><TD VALIGN=TOP><img src=/assets/images/bullet.gif width=10 height=8></TD><TD><FONT FACE=VERDANA,ARIAL,HELVETICA,SANS-SERIF SIZE=2><A HREF=/view_top.php3?id=$id>$title</A><BR>$description</TD></TR>\n <TR><TD VALIGN=TOP COLSPAN=2><img src=/assets/images/spacer.gif width=10 height=6></TD></TR>\n "; }; if($results <= 0) { print " <TR><TD><FONT FACE=VERDANA,ARIAL,HELVETICA,SANS-SERIF SIZE=2>NO RESULTS</TD></TR>\n <TR><TD VALIGN=TOP COLSPAN=2><img src=/assets/images/spacer.gif width=10 height=6></TD></TR>\n "; } ?>try... <? $results = mysql_db_query("$db", "select * from $table where $query order by update_datetime desc limit $offset, 10"); while($one = mysql_fetch_array($results)){ $id=$one["id"]; $title=$one["title"]; $description=$one["description"]; if($results <= 0) { print " <TR><TD><FONT FACE=VERDANA,ARIAL,HELVETICA,SANS-SERIF SIZE=2>NO RESULTS</TD></TR>\n <TR><TD VALIGN=TOP COLSPAN=2><img src=/assets/images/spacer.gif width=10 height=6></TD></TR>\n "; else { print " <TR><TD VALIGN=TOP><img src=/assets/images/bullet.gif width=10 height=8></TD><TD><FONT FACE=VERDANA,ARIAL,HELVETICA,SANS-SERIF SIZE=2><A HREF=/view_top.php3?id=$id>$title</A><BR>$description</TD></TR>\n <TR><TD VALIGN=TOP COLSPAN=2><img src=/assets/images/spacer.gif width=10 height=6></TD></TR>\n "; }; } ?> The if should be before the print statement. You want it to compare then print, not print then compare. Alnisa -- ......................................... Alnisa Allgood Executive Director Nonprofit Tech (ph) 415.337.7412 (fx) 415.337.7927 (url) http://www.nonprofit-techworld.org (url) http://www.nonprofit-tech.org (url) http://www.tech-library.org ......................................... Nonprofit Tech E-Update mailto:nonprofit-tech-subscribe@egroups.com ......................................... applying technology to transform .........................................