Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: insert data

  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    insert data

    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

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll need to add the code to insert the data into your database, but this should generate the numbers for you:

    PHP Code:
    <?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

  • #3
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks

    Yep thanks for your help ! I manage to do it!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •