Home > Archive > PERL Beginners > May 2004 > multiple pages results
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
multiple pages results
|
|
| Cristi Ocolisan 2004-05-24, 6:32 am |
| Hello everybody,
While interrogating a MySQL database, I'm trying to split the results into
multiple pages.
I don't know where I'm going wrong. When I run the script below, only the
number of pages is printed on screen.
Can anyone help?
#!/usr/bin/perl
use CGI ":all";
use DBI;
my $query = new CGI;
print $query->header;
my $user = "root";
my $pass = "";
my $source = "DBI:mysql:chestie";
my $dbh=DBI->connect($source, $user, $pass, {RaiseError => 1});
my $sql = qq{SELECT parola FROM parole};
my $sth = $dbh->prepare($sql);
$sth->execute;
$count = 0;
while (my @row = $sth->fetchrow_array()){
push(@nume,$row[0]);
$count++;
}
$sth->finish;
my @results = @nume;
#print "@results <br>";
$result_count = $count;
#print "result_count = $result_count<br>";
$pagesize = 2;
$reqpage = 1;
if ($result_count != 0) {
$pagecount = int($result_count / $pagesize);
if (($pagecount * $pagesize) != $result_count) {
$pagecount++;
}
}
$firstresult = (($reqpage - 1) * $pagesize) + 1;
$lastresult = $firstresult + $pagesize - 1;
if ($lastresult > $result_count) {
$lastresult = $result_count;
}
$prev_page = $reqpage - 1;
$next_page = $reqpage + 1;
if ($reqpage == 1) {
$prev_link = "";
} else {
$prev_link = " <a
href=\"http://www.wiq.ro/cgi-bin/rointera/gigi1.cgi?reqpage=$prev_page&pages
ize=$pagesize\">" . "PREVIOUS" . "</a>";
}
if ($reqpage == $pagecount) {
$next_link = "";
} else {
$next_link = " <a
href=\"http://www.wiq.ro/cgi-bin/rointera/gigi1.cgi?reqpage=$next_page&pages
ize=$pagesize\">" . "NEXT" . "</a>";
}
if ($pagecount > 1) {
$pagelinks = $prev_link;
$pageno = 0;
while ($pageno < $pagecount) {
$pageno++;
if ($pageno == $reqpage) {
$thislink = " <b>$pageno</b> ";
} else {
$thislink = " <a
href=\"http://www.wiq.ro/cgi-bin/rointera/gigi1.cgi?reqpage=$pageno&pagesize
=$pagesize\">" . $pageno . "</a>";
}
$pagelinks = $pagelinks . $thislink;
}
$pagelinks = $pagelinks . " " . $next_link;
} else {
$pagelinks = "";
}
#print "pagina este $reqpage<br>";
print "$pagelinks";
________________________________________
_
Cristi Ocolisan
| |
| Jupiterhost.Net 2004-05-24, 6:32 pm |
|
Cristi Ocolisan wrote:
> Hello everybody,
>
>
>
> While interrogating a MySQL database, I'm trying to split the results into
> multiple pages.
>
>
>
> I don't know where I'm going wrong. When I run the script below, only the
> number of pages is printed on screen.
>
>
>
> Can anyone help?
You may want to check out Data::Page and/or Data::Pageset
HTH:)
Lee.M - JupiterHost.Net
|
|
|
|
|