Re: while loops?
- From: "Kimmo Laine" <spam@xxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 13:27:58 +0300
"Patrick" <psmith@xxxxxxxxxxxxxx> wrote in message
news:e5hmne$l9v$1@xxxxxxxxxxxxxxxx
I'm trying to while loop using a flat txt file and write the values out
into a form. I have 50-58 values to echo. Am I going to have to echo each
line of html. Or is there a way to make this work between the php. Right
now it wants to write the whole table over and over. Is my logic screwed
up? I am not a programmer as such but can get by. I have something like
this which is an abbreviated version. Any help would be appreciated.
Thanks,
Patrick
<html>
<head>
<?
$filename = "C10AB_precruise.log";
$larray = file($filename);
?>
</head>
<body>
<?
$i=0;
while ($i <= 60)
{
?>
<form method="post" action="precmlog.php">
<table width="800" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="40%">
Log *** completed by:<br> <input class="inform" type="text" size="30"
name="person" value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
<tr>
<td>
Cruise name/number:<br> <input class="inform" type="text" size="30"
name="cruisenum" value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
<tr>
<td>
Ship name:<br> <input class="inform" type="text" size="30"
name="shipname" value="<?php echo $larray[$i]; ?>"><br>
</td>
</tr>
</table>
<input class="button" type="submit" value="Submit">
</form>
<?
}
$i++;
?>
</body>
</html>
$i++ should be INSIDE the while loop to have effect. Now you don't increase
it so it keeps writing the same form over an over again because $i gets no
bigger and therefore it's always less than 60 thus it becomes an infinite
loop.
fix
<?
} // Loop stops here, $i is never reached.
$i++;
?>
to
<?
$i++; // Now it's inside the loop and is incremented
}
?>
Or even better, use a for-loop instead. That way you'll do all the necessary
loop-control in one logical place:
for($i=0; $i<=60; $i++) { ....
HTH
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@xxxxxxxxxxxxx | Gedoon-S @ IRCnet | rot13(xvzzb@xxxxxxxxxxxxx)
.
- Prev by Date: Re: Different binary results with different PHP versions
- Next by Date: Re: Different binary results with different PHP versions
- Previous by thread: Re: while loops?
- Next by thread: Mambo or Joomla?
- Index(es):