Need help with code

Discussion in 'PHP' started by deriklogov, Nov 20, 2009.

  1. #1
    I have array containing some information including information about mysql table. Sample:

    $ready[1][name1]='Mikle';
    $ready[1][db_table]='namelist1';

    $ready[2][name1]='Mikle2';
    $ready[2][db_table]='namelist1';

    $ready[3][name1]='Mikle3';
    $ready[3][db_table]='namelist1';


    $ready[4][name1]='Alex';
    $ready[4][db_table]='namelist2';

    $ready[5][name1]='Jack';
    $ready[5][db_table]='namelist1';

    $ready[6][name1]='Lowes';
    $ready[6][db_table]='namelist6';


    What I need to do is to make cycle thru array :
    to do that I am counting number of items in array

    $numberitems=count($ready)

    and doing cycle thru all of them:

    for ($row = 0; $row < $numberitems; $row++)

    {}


    What I need help with is in that cycle I need to group items lets say in group of 200 and make a bulk insert into mysql.
    So lets say when we get to first item

    $ready[1][db_table]='namelist1';

    we can see that its going to table = namelist1

    and second item going to the same table, but fifth item going to different name.

    so script should collect lets say 200 records which are going to one table and insert them in bulk like
    INSERT (....) VALUES ( ...........),(..........) ... and so on



    NEED YOUR HELP TO DO THAT, PLEASE PLEASE PLEASE
     
    deriklogov, Nov 20, 2009 IP
  2. RichPirate

    RichPirate Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well first off you should use the foreach statement

    so to go through the array it would be

    foreach($ready as $current) {

    foreach($current as $entry) {

    $statement[] = "INSERT INTO {$entry['db_table']} //.....etc

    }

    }
     
    RichPirate, Nov 20, 2009 IP
  3. deriklogov

    deriklogov Well-Known Member

    Messages:
    1,080
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    130
    #3
    the thing is , lets say I have in array 100,000 records, those records should be divided into INSERT INTO .... VALUES ( 1) ..... 200 values (200) per each query (bulk mysql insert), and all those 100,000 should be going into right insert depends on table which those are going to.
     
    deriklogov, Nov 20, 2009 IP