It is not very hard.

You can use an sql statement like this:

my $sth = $dbh->prepare("select id, name, age, bla from table order by name
limit ?, ?");
$sth->execute($skip, $show);

You can get the number of rows you want to skip ($skip) and the number of
rows you want to show ($show) using the CGI package like:

USE  CGI;
my $q = new CGI;
my $skip = $q->param('skip');
my $show = $q->param('show');

You can check first the total number of rows that could be displayed, then
you can compare, and if the total number of rows is bigger than the $skip +
$show, meaning the latest record printed in the current page, then you can
print a "Next" link, and ... do the same with the "previous" link....


Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

----- Original Message -----
From: "Dennis Stout" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, July 28, 2003 5:39 PM
Subject: Re: How to display multiple web pages depending on


> I want to write a subroutine to select the contain of MySQL database and
> display the result on the browser.
> But I'm not sure how to get it create multiple pages if the list exceeds
> a given number; say 50, and create a link to the next page: like "Next"
> or "1 2 3". I think it should be easy - but I've never seen codes like
> that before.

The idea is you create a ranged loop.

for (x..x+y) {
  #blah
}

#blah is where you put all your code for retrieving lines from the SQL dbase
and HTMLize them and return them.

x is obtained through CGI params

my $q = new CGI;
my $start = $q->param('start');

x+y is obtained however

1-
my $end = $start + $q->param('amount_per_page');
2-
my $end = $start + 50;

whichever.

Then;

for ($start..$end) {
    #grab from db, htmllize, append to scalar variable...
}


print <<EOF;
<center>
<table>
$scalar_from_for_loop
</table>
</center>
EOF

and, yeah...

Should put you on the right track.  I wrote my own customized interface to
SQL
(actually its an interface to the normal DBI interface, heh..) so I didn't
write that portion since what I use would not at all be like what you would
use.

Dennis


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