>> Some where it resets back to zero all the time

You do "foreach $row", then you set all of your variables to pieces of "@$rows".
Note the trailing 's'.  Typo strikes again.  All of those values are probably
undefined, since I assume "$rows" is undefined, thus they get inserted as 0 or
''.

Simply logging your query, or just printing your variables to an error log or
the screen as a first debugging step should have pointed this out pretty
quickly.

If all of the processing that you are doing on the result set happens on a row
by row basis, it is probably more effecient to use a fetchrow_hashref loop to
step through your initial query result set and do the update rather than
fetching everything to an in-memory array and then looping through that.

Also, if all you want to do is increment a numerical field, you may be able to
do that directly in the SQL by using:

"update media1 set history5 = history5 + 1 where ...  "


--Adam

----- Original Message -----
From: "FLAHERTY, JIM-CONT" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 02, 2002 9:59 PM
Subject: What am I doing wrong... I want to increment a number in a DB


I have a query to draw it out on my redhat 7.1 box with MySQL 3.23 and I
increment it and run update query . Some where it resets back to zero all
the time

the code


foreach $row(@$array_ref) {
  my($num,$title,$media,$serial,$time,$class,$remarks,$custody,$loc,
$format,$qty,$lab,$rew,$sta,$history5,$check) = @$rows;

$history2 = $history5;
$history2++;

}
$dbh2 =DBI ->connect($data_source, $username, $password);
my $sth2 = $dbh2 -> prepare("update media1 set history5 ='$history2' where
num =
 '$num'");


$sth2 -> execute or die " unable to execute query ";






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to