in reply to Re: Loop Question
in thread Loop Question

I think you're getting closer
$SqlStatement=$db->prepare("SELECT TransDate, TransPmtAmt FROM Cust_ac +t_da WHERE CustomerNumber = ? AND TransType = 'P'") or die "prepare f +a +iled: " . $db->errstr()."\n";
good. the die is a plus.
$SqlStatement->execute($CustomerNumber);
good. maybe a die here.
while ( @stuff = $SqlStatement->fetchrow() ) {
good. this fixes the seemingly infinite loop that appeared in your first code.
# do things with @stuff $FormatTransDate = substr($TransDate, 0, 10); $FormatTransPmtAmt = sprintf("\$%.2f", $TransPmtAmt); print $FormatTransDate; print "    "; print $FormatTransPmtAmt; }
This is a problem, though. You go to all the trouble of preparing, executing and retrieving data, but where do you use it?
See, the row you're currently working on is stored in @stuff, but you never do anything with it. Do you expect $TransDate, $FormatTransDate and $FormatTrnasPmtAmt to hold information from the database? They're not going to. At least, not from the snippet you posted. If they're defined somewhere else in the code, tell us, and say what they're used for.
Either assign them values from @stuff or use @stuff directly.
I'm willing to help you, but this is a little much... If you have more questions, please, let me know you looked in DBI's POD, or in perl's reference, or perlvar or somewhere. I don't know what you're doing, or why you're changing things, because the alterations have fixed one thing, but then broken another, or just don't make sense. We can try to make this work, but you gotta reach half-way, OK?

Replies are listed 'Best First'.
Re: (boo) loop analysis
by quietone (Initiate) on Mar 22, 2001 at 00:38 UTC
    Okay...i ran this code and i die after the sql statement. Is this because I am not using the DBI interface??? Is there a way to do this without the DBI interface? I see what you are saying about the @stuff.... The 2 format variables are defined in that loop. $TransDate and $TransPmtAmt is supposed to be variables used to get data from the columns TransDate and TransPmtAmt in the database. So in order to get that information I have to do this:
    $TransDate=$stuff[1]; $TransPmtAmt=$stuff[2]; $FormatTransDate = substr($TransDate, 0, 10); $FormatTransPmtAmt = sprintf("\$%.2f", $TransPmtAmt); print $FormatTransDate; print "    "; print $FormatTransPmtAmt;