> -----Original Message-----
> From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 07, 2001 7:58 PM
> To: Beginners (E-mail)
> Subject: DBI Perl and rows...
> 
> 
> List,
> 
> I have the following code here....
> 
> my $sth = $dbh ->prepare( qq{ SELECT * FROM
>                                 table_name
>                                 WHERE status <> 'DELETED' AND 
> status <>
> 'COMPLETE'
>                                 ORDER BY status
>                                } ) || die $dbh->errstr; ;
>   $sth->execute;
>   my $entries;
>   my $truth = $sth->rows;
>   if ($truth == 0 ){
>       print<<HTML;
>       NO DATA IN DATABASE
> HTML
>       }elsif ($truth >= 1 ){
>       print<<HTML
>       THERE ARE $truth ROWS IN THE DATABASE!
> HTML
> }
> 
> 
> Now what I really want to be able to do is only display 10 of 
> the rows in
> the database then create a hyperlink to to the next 10 and so on.
> 
>   my $truth = $sth->rows;
>   if ($truth == 0 ){
>       print<<HTML;
>       NO DATA IN DATABASE
> HTML
>       }elsif ($truth >= 1 BUT LESS THAN 10 ){
>       print<<HTML
>       THERE ARE $truth ROWS IN THE DATABASE!
>       PLEASE PRESS HERE TO SEE THE NEXT 10 ENTRIES ($hyperlink)
> HTML
>       }elsif ($truth >= 11 BUT LESS THAN 20)
>       print<<HTML
>       SELECT HERE TO SEE NEXT 10 ENTRIES IN DATABASE
>       <a href="link.cgi?show_next=next)
>       }
> 
> Does this make sense to any one.  I have been 'straining' my 
> brain for a
> couple of days on this one.

Note that the $sth->rows method generally will NOT work with SELECT
statements unless you actually fetch all the rows. Most databases don't know
how many rows will be returned until you fetch them. See the DBI docs for
more details.

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

Reply via email to