At 1/3/2003 12:25 AM, Lightfirst wrote:

Can someone explain to me why the loop that counts to 99 appears before the
5 by 5 grid in the following php code?

Yes.

## else {
## echo "<td align=\"center\" valign=\"middle\" width=\"15%\" height=\"77\" border=\"1\" bordercolor=\"#000000\">";
## echo "<div align=\"center\"><font size=\"1\"></font></div>";
## echo "Hello" ; $i++;
## } //for else

You start the <TD> tags, but whenever your conditional echoes "Hello," you're not echoing the </TD>. And when you come out of your loop, you never close your <TABLE> tag. I hope you also realize that you're opening and closing that <DIV> and <FONT> without putting the "Hello" inside of it.

Here's a good tip someone gave me when I first started learning PHP: when you're dealing with HTML, it's a good idea to use \n at the end of your echoed lines and \t's at the beginnings to create staggered indentations, this makes it a little easier to read when you're testing the output.

For example, try running this version of your code:

<?php
echo "<table border=\"1\" align=\"center\" width=\"100%\" bgcolor=\"#FFFFFF\" bordercolor=\"#FFFFFF\">\n\t<tr>\n";
for ($r=0; $r<5; $r++){
for ($c=0; $c<7; $c++){
if ($c==0 || $c%7==0)
echo "\t\t<td align=\"center\" valign=\"middle\" width=\"15%\" height=\"77\" bordercolor=\"#000000\"></td>\n";
else if ($c%6==0)
echo "\t\t<td align=\"center\" valign=\"middle\" width=\"14%\" height=\"77\" bordercolor=\"#000000\"></td>\n\t</tr>\n\t<tr>\n";
else {
echo "\t\t<td align=\"center\" valign=\"middle\" width=\"15%\" height=\"77\" border=\"1\" bordercolor=\"#000000\">\n";
echo "\t\t\t<div align=\"center\"><font size=\"1\">";
echo "Hello" ; $i++;
echo "</font></div>\n\t\t</td>\n";
} //for else
}// for loop c
} //for loop r
echo "\t</tr>\n</table>\n\n";
for ($i=1; $i<100; $i++)
echo "$i<br>\n";
?>

Hope this answers some of your questions.
--
S. Keller
UI Engineer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Pkwy.
Anchorage, AK 99508
907.770.6200 ext.220
907.336.6205 (fax)
Email: [EMAIL PROTECTED]
Web: www.healthtvchannel.org


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to