...

View Full Version : The while loop



stophon4
05-19-2004, 01:54 AM
I cant do this while loop in a array, it doesn't work, maybe it is the while loop, but I am pretty sure that it is the while loop not working how I am doing this, probably syntax error.


$authorize = '1';
$authorized = count(file("authorized.dat"));
$authorized_IP = file("authorized.dat");
while($authorize >= $authorized){
echo ("<OPTION value='$authorize'>");
echo $authorized_IP[$authorize];
$authorize++;
}


I think it is this line:


echo $authorized_IP[$authorize];

How can I fix this?

l3vi
05-19-2004, 02:23 AM
What kind of errors do you get when you run this script?

l3vi
05-19-2004, 04:15 AM
Okay, got it! You cant use the while look on this, you must use the for loop. At least with what I got.. :D



<?php
$x = '1';
$authorized = file("authorized.dat");
$authorized = count($authorized);
$authorized_IP = file("authorized.dat");
for ($x = 1; $x < $authorized; $x++) {
echo ("<OPTION value='$x'>");
echo $authorized_IP[$x];
echo ("<br>");
}
?>


Hope that helps!

firepages
05-19-2004, 06:06 AM
your code should work ... but

>= should be <=

else your loop will never start in the first place , also $authorize should be initialised as 0 since thats where the array index starts (unless the first line is simply descriptive/metadata);

sad69
05-19-2004, 09:23 PM
$authorize = '1';


Just wondering why there would be quotes here... you're wanting to increment a string? Get rid of the quotes and also do what firepages said..

Let us know how that works out for you.

Sadiq.

stophon4
05-19-2004, 11:25 PM
Just had to do what firepages said, then it worked great, and that will help me alot in the future probably ;)

I didn't know you could do that with arrays :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum