Hello redhat, Hey... look at this: CREATE TABLE `testip` ( `id` int(10) unsigned NOT NULL auto_increment, `theip` varchar(100) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `theip` (`theip`) ) TYPE=MyISAM AUTO_INCREMENT=7 ; SELECT theip, SUBSTRING_INDEX( theip, ".", 1 ) *1 AS one, substring_index( SUBSTRING_INDEX( theip, ".", 2 ) , ".", -1 ) *1 AS two, substring_index( SUBSTRING_INDEX( theip, ".", 3 ) , ".", -1 ) *1 AS three, SUBSTRING_INDEX( theip, ".", -1 ) *1 AS four FROM `testip` ORDER BY one, two, three, four And you have all ip's ordered by number... so you can do: <?php $Result=mysql_query("Select theip, SUBSTRING.....", $db); $lastgroup="0.0.0"; $key=255; while(list($theIP,$one,$two,$three,$four)=mysql_fetch_row($Result)) { if ($lastgroup<>"$one.$two.$three") { while ($key<80) echo "$lastgroup." . ($key++) . " is free<br>\n"; $key=1; } while ($key<($four*1)) echo "$one.$two.$three." . ($key++) . " is free<br>\n"; echo "$one.$two.$three.$four IS NOT FREE<br>\n"; $lastgroup="$one.$two.$three"; $key++; } while ($key<80) echo "$lastgroup." . ($key++) . " is free<br>\n"; ?> P.S. I DONT KNOW IF THIS IS TOO SLOW.. you might test.. -- Best regards, Pablo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php