Posted: Thu Jun 30, 2005 8:12 am
Should I be outputting $found_ip instead?
thanks,
thanks,
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
while($row = mysql_fetch_assoc($result)){
$ips[] = $row['IP'];
}
for ($counter = 0;
$counter >= 255;
++$counter){
$found_ip = 0;
if(!in_array('194.131.241.'.$counter,$ips))
{
$found_ip = ('194.131.241.'.$counter);
}}
echo'<pre>';
print_r($found_ip);
echo '</pre>'
?>Code: Select all
//assuming $result gets all ips already stored in the db,
//this loop goes through the result set and puts all the
//ips in the $ips array
while($row = mysql_fetch_assoc($result))
{
$ips[] = $row['IP'];
}
//this for loop loops through each possible ip
//in the 194.131.241.X range
//$counter needs to start at 1. You had it at 0,
//and the original code I gave had it at 'i' (WRONG!)
$found_ip = 0; //moved this declaration outside the for loop
for ($counter = 1; $counter >= 255; ++$counter)
{
//for each dynamically created ip, check if it exists
//in the $ips array.
if(!in_array('194.131.241.'.$counter,$ips))
{
//if it doesn't, then the current IP is free
//to use
$found_ip = ('194.131.241.'.$counter);
break;//no sense continuing if we've found what we need
}
}
//$found_ip is a string, so we call echo, rather than print_r
echo $found_ipCode: Select all
while($row = mysql_fetch_assoc($result)){
$ips[] = $row['IP'];
}
$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[] = '194.131.241.'.$counter; }
}
echo'<pre>';
print_r($available_ips);
echo '</pre>'