Page 1 of 1

My For loop headache, please help

Posted: Fri Jul 01, 2005 8:10 am
by mhouldridge
Hi,

Here is my for loop for showing available IP addresses within my database. It creates an array with the taken ones and looks for available ones within the range ---- WELL, AT LEAST THAT IS WHAT IT SHOULD DO :-)

Code: Select all

$found_ip = 0;
for($counter = 1; $counter >= 255; ++$counter){
if(!in_array('192.168.241.'.$counter,$ips)){
$found_ip = ('192.168.241.'.$counter);									
 
 }
}
							
echo $found_ip;
The echo $found_ip outputs a result of zero. It appears to be taking the variable from the first line without using the For loop. I need to combine the $found_ip with the For loop somehow.

Please help

Posted: Fri Jul 01, 2005 8:44 am
by djot
Your for loop was wrong.

Code: Select all

for($counter = 1; $counter <= 255; $counter++){

Posted: Fri Jul 01, 2005 8:49 am
by djot

Code: Select all

$found_ips=ARRAY();
$available_ips=ARRAY();

for($counter = 1; $counter <= 255; $counter++)
{
  if(in_array('192.168.241.'.$counter,$ips))
  {
    $found_ips[] = '192.168.241.'.$counter;
  }
  else
  {
    $available_ips[] = '192.168.241.'.$counter;
  }
}

Posted: Fri Jul 01, 2005 9:01 am
by mhouldridge
Excellent - that's done it.

Thanks for your help.

ps - How long did it take you to understand php?

Posted: Fri Jul 01, 2005 9:27 am
by Chris Corbyn
mhouldridge wrote:Excellent - that's done it.

Thanks for your help.

ps - How long did it take you to understand php?
How long is a piece of string? When does one "understand" PHP? You're constantly learning, everybody is. You just gain knowledge and experience ;)