Oh, okay. By the way, you should check out the [EMAIL PROTECTED] list. -----Original Message----- From: Andrew Gaffney [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 29, 2003 9:18 AM To: [EMAIL PROTECTED] Subject: Re: DBI
I had a good reason for doing that. I have information that I need to get from 2 separate lines in the db. I wasn't able to write a query that could join them together. Tim Johnson wrote: > Another way to do it is: > > while($ref = $sth->fetchrow_hashref){ > do something... > } > > -----Original Message----- > From: Andrew Gaffney [mailto:[EMAIL PROTECTED] > Sent: Tuesday, October 28, 2003 10:00 PM > To: [EMAIL PROTECTED] > Subject: Re: DBI > > > Andrew Gaffney wrote: > >>Is there anything wrong with this code? >> >>my $sth = $dbh->prepare($query); >>$sth->execute; >>my $ref = $sth->fetchrow_hashref; >>while($ref) { >> $totalhrs += $ref->{quantity}; >> my $tmpdate = $ref->{id}; >> $tmpdate =~ s/(\d{4})(\d{2})(\d{2})\d+/$2-$3-$1/; >> print >>"<tr><td>$tmpdate</td><td>$ref->{item}</td><td>$ref->{quantity}</td>"; >> $ref = $sth->fetchrow_hashref; >> if($ref->{id} eq $lastinvid) { >> print "<td>$ref->{fname} $ref->{lname}</td></tr>\n"; >> $ref = $sth->fetchrow_hashref; >> } else { >> print "<td>N/A</td></tr>\n"; >> } >> $lastinvid = $ref->{id}; >>} >> >>I get this error over and over again in my Apache log: >> >>DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at >>/home/httpd/cgi-bin/report-myflights.pl line 38. [Tue Oct 28 22:13:06 >>2003] [error] 17457: ModPerl::PerlRun: DBD::mysql::st fetchrow_hashref >>failed: fetch() without execute() at >>/home/httpd/cgi-bin/report-myflights.pl line 38. >> >>It will cycle through the loop like 10 times and then die. I get >>output >>and an Apache error message all in one page. BTW, line 38 is the first >>'$ref = $sth->fetchrow_hashref' in the while loop. > > > Nevermind, it was my own fault. It was running out of input. I changed > that line to: > > if(!($ref = $sth->fetchrow_hashref)) { > last; > } > -- Andrew Gaffney -- 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]