loretta
06-08-2005, 12:42 PM
Hi, I'm newbie with php and mysql. I would like to insert automatically a sequence of numbers in a mysql table .. can somebody help me?
Ex. the numbers/data I have to insert are ip adresses so something like 161.65.32.1 .... to 161.65.32.255.
Is it possible to do it automatically?
Thanks
delinear
06-08-2005, 01:05 PM
You'll need to add the code to insert the data into your database, but this should generate the numbers for you:
<?php
$start_ip = '161.65.32.1';
$end_ip = '161.65.32.255';
$start_array = explode('.', $start_ip);
$end_array = explode('.', $end_ip);
$i = 0;
while($i < 1) {
$data = implode('.', $start_array);
// insert your data into the database
if($start_array[0] < 255) {
if($start_array[1] < 255) {
if($start_array[2] < 255) {
if($start_array[3] < 255) {
$start_array[3] += 1;
} else {
$start_array[3] = 1;
$start_array[2] += 1;
}
} else {
$start_array[2] = 1;
$start_array[1] += 1;
}
} else {
$start_array[1] = 1;
$start_array[0] += 1;
}
}
if($start_array[0] == $end_array[0]) {
if($start_array[1] == $end_array[1]) {
if($start_array[2] == $end_array[2]) {
if($start_array[3] == $end_array[3]) {
$i=1;
}
}
}
}
}
?>
Hope that helps :)
loretta
06-09-2005, 12:42 PM
Yep thanks for your help ! I manage to do it!!! :thumbsup: