#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    1
    Rep Power
    0

    I have a table which contains 3 records.
    When I display the total number of rows selected, it is 3.
    But when I try inserting into another table, it only insert one row.

    Can anybody please help me.


    $sth = $dbh->prepare("SELECT id FROM tab1 WHERE parentid = '1'");

    $sth->execute()
    $rv = $sth->rows;

    my @row;
    while ( @row = $sth->fetchrow_array( ) ) {
    $sth = $dbh->prepare("INSERT INTO tab2(id) VALUES ('@row')");

    $sth->execute()
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    Well 1st of all, there's no need to recreate the prepare statement every time, that's why you use a prepare statment.

    $sth = $dbh->prepare("INSERT INTO tab2(id) VALUES ('?')");
    while ( my @row = $sth->fetchrow_array( ) ) {
    $sth->execute(@row);
    }

    That's not tested, but give it a try.

IMN logo majestic logo threadwatch logo seochat tools logo