[thelist] PHP - While Loop

Kath Kath at cyber-kat.com
Sat Aug 16 10:55:53 CDT 2003

Hi again - sorry this exchange got derailed by the Great Blackout of 2003.
We were without power from a little after 4pm EDT to 7:30am - major pain.
After the power came back on, they asked us not to use appliances unless
absolutely necessary.  I chose fans over my computer - what can I say the
PC generates heat and I hate being hot <g>.

Anyway - back to my problem with the While loop ...

At 01:01 PM 8/14/2003 -0500, Keith wrote:
>Have you tried putting parentheses around the math expression?
>echo "  <td align='right'>".($distance / 10)."</td>\n</tr>\n";

Didn't work :- (

>If that doesn't work, could you post the actual source the php generates?

This is what appears between the BODY tags on "view source"
<table border="0" cellpadding="3">
  <td bgcolor="#CCCCCC" align="center">Distance</td>

  <td bgcolor="#CCCCCC" align="center">Cost</td>
$distance = 50;
while ($distance <= 250 )
  echo "<tr>\n  <td align='right'>$distance</td>\n";
  echo "  <td align='right'>". $distance / 10 ."</td>\n</tr>\n";
  $distance += 50; 

Looks like it is not interpreting the PHP correctly.

When I load the page from my web host server, it looks like this ...
<table border="0" cellpadding="3">
  <td bgcolor="#CCCCCC" align="center">Distance</td>

  <td bgcolor="#CCCCCC" align="center">Cost</td>
  <td align='right'>50</td>
  <td align='right'>5</td>
  <td align='right'>100</td>
  <td align='right'>10</td>

  <td align='right'>150</td>
  <td align='right'>15</td>
  <td align='right'>200</td>
  <td align='right'>20</td>

  <td align='right'>250</td>
  <td align='right'>25</td>

All of the other PHP I have done since I started with the book has worked

I have done mostly input forms with a page to display the output.  I even
got adventurous and tried to add some things that were not part of the
tutorial.  All worked fine until I came to this.

Anthony had asked ...
>Obvious question: what extension is your file? Is IIS set to parse that for 

I have Apache set up, so I'm not using IIS for the PHP environment.

I should mention again that this is not code I wrote.  It is an example
from the CD that came with the book.  I was wondering if there wasn't
something wrong with it until I uploaded it to my web space and it worked.

Well thanks again for all your suggestions.  I'm assuming the code is
correct since it works on my web host server, but I sure would love to know
why it's not working on my system.

Kath ...  "A patriot must always be ready to defend his country against its
government."  -Edward Abbey, naturalist and author (1927-1989)
Established 1995 --> www.cyber-kat.com

More information about the thelist mailing list