Re: help with consecutive numbers in db
| From: | Pablo M. Rivas | Date: | Thu, 24 Jun 2004 22:14:50 +0000 |
| Subject: | Re: help with consecutive numbers in db | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34943@lists.php.net to get a copy of this message | ||
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