Helpful Information
 
 
Category: Perl Programming
insert into in a loop

Below is a section of my script, I want it to loop through the select query and insert the results into a temp table that has an incremented id, only what happens is that it only inserts 1 row when there should be over 100; does anybody know why, or can you only insert 1 row at a time hence the insert into statement does not work in a loop.

Any ideas would be most welcome

$sth = $dbh->prepare("select Customer.CustID,
Customer.CustName,
Customer.Trade,
Customer.SalesPersonnelID
FROM Customer
");

$sth->execute;


while (@row=$sth->fetchrow)

{

print "<tr><td>$i</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td></tr>";

$sth = $dbh->do("INSERT INTO temp1 (Rangeid,SalesPersonnelID,
CustName,
Trade )
VALUES ($i,
$row[3],
'$row[1]',
'$row[2]')") &#0124; &#0124; die print "problem with the insert query";



$i = $i+1;

}










privacy (GDPR)