The answer to this is probably in your DBMS. What DBMS are you using.
Different ones have different ways to page the data. Using MySQL you need to
use the LIMIT keyword to specify how many rows to skip, and how many to
return (when two parameters are used with limit).

Using MSSQL 7.0 or later you would use something like this:

 SELECT TOP 10 * FROM
                                table_name
                                WHERE status <> 'DELETED' AND status <>
'COMPLETE' AND status NOT IN
        (SELECT TOP 100 status FROM table_name)
                                ORDER BY status


        That might be a little tricky unless you use an identity column
specifically for sorting and thus paging - otherwise you might not get all
the rows you are looking for.

That would give you rows 101-110.

You would probably use a hidden field or append a parameter on the URL to
let you know which rows were being searched for next. That will allow you to
page through as the user moves forward or back through the results.

Check your DBMS's docs for how to page or limit return from a query.

Steve H.


-----Original Message-----
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 6: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.

Kind regards,

Daniel Falkenberg

==============================
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:    http://www.vintek.net
Tel:    (08) 8523 5035
Fax:    (08) 8523 2104
Snail:  P.O. Box 312
        Gawler   SA   5118
==============================


--
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