I'm converting a bash cgi script to php on apache webserver. For whatever reason I have a for loop that doesn't want to execute. I've tried comparing it to other loops I've done in the past and it seems like it should work but nothing shows up on the page in the source code. It's just an empty area. I also put an echo in the code to echo out which number it's on, but those didn't show up either. Anybody see where I'm going wrong?
for($i=$begin; $i>=$end; $i++) {
echo "$i
";
echo "<td>somedata$i</td></tr><tr>
";
}
I've already verified the variables begin and end show up by echoing them just before the loop. Once I hit the loop it's not executing that code. Everything after the loop executes fine as well. I'm also not getting any errors in the apache log files, which is what really is frustrating. Any help would be appreciated.
Thanks!
I think that you should replace >=
to <=
i supposed that
$begin =5;
$end = 0;
then you should used decrements $i--
with >=
for($i=$begin; $i>=$end; $i--) {
echo "$i
";
echo "<td>somedata$i</td></tr><tr>
";
}
if
$begin = 0;
$end = 5;
then you should less than equal to <=
with increment $i++
for($i=$begin; $i<=$end; $i++) {
echo "$i
";
echo "<td>somedata$i</td></tr><tr>
";
}
I am not sure about the values both the variable have, but you need to change the >=
sign to <=
so that the loop can go until $i
goes up to the $end
value.
for($i=$begin; $i<=$end; $i++) {
echo "$i
";
echo "<td>somedata$i</td></tr><tr>
";
}
Your code is use incremental for $i and in your logic you use >=$end I think you have to change it to $i
for($i=$begin; $i<$end; $i++) { echo "$i
"; echo "<td>somedata$i</td></tr><tr>
";
Change either >=
to <=
or make it a decrement loop by changing i++
to i--
Both will work.