Thanks for your reply graff. The first if statement was because I parsed the form at one point. I have cleaned up the script, and got rid of anything I don't need and I am still having the same problem. I tried putting reqpage in the page links, but still no luck.
I'm thinking the problem is with the links. I am having a hard wrapping my brain on how to create these links properly and what exactly I should be putting in them. I'm sure I am close to getting this working, so any help would be much appreciated. I have attached the updated script.
Thanks in advance.
#!/usr/bin/perl use CGI qw(:standard); use DBI; use warnings; use strict; my (@row,$name,$path,$dsp,$count); my $query = new CGI; print $query->header('text/html'); print qq~ <!DOCTYPE html> <html> <head> <title>Movie Search</title> </head> <body> <br /><br />~; my $reqpage = $query->param('reqpage') || '1'; param('per_page'); #Get total amount of rows from db my $dbh=DBI->connect($connectionInfo,$user,$passwd); my $num_rows= $dbh->selectrow_array('select count(name) from video + order by name'); my $num_results_perpage = 25; # calculate the number of pages to show my $pagecount = int($num_rows / $num_results_perpage); if (($pagecount * $num_results_perpage) != $num_rows) { $pagecount++; } # calculate which results to show in the page my $firstresult = (($reqpage - 1) * $num_results_perpage) + 1; my $lastresult = $firstresult + $num_results_perpage - 1; if ($lastresult > $num_rows) { $lastresult = $num_rows; } # sql limit starts at 0 my $start_point = $firstresult - 1; my $sth = $dbh->prepare("Select name,path from video order by name + LIMIT $start_point,$num_results_perpage"); $sth->execute(); while (@row = $sth->fetchrow_array()) { $name = $row[0]; $path = $row[1]; $path =~ s/'/%27/g; $dsp = substr $path, 27, 255; print "<a href='/media/$dsp'>$name</a> <br />"; $count=$count+1; } $sth->finish(); # page links my ($prev_link, $next_link, $pagelinks, $pageno, $thislink, $pages +ize); my $prev_page = $reqpage - 1; my $next_page = $reqpage + 1; if ($reqpage == 1) { $prev_link = ""; } else { $prev_link = " <a href=\"http://path/to/script.cgi?reqpage=$re +qpage=$prev_page\">". "previous" . "</a>"; } if ($reqpage == $pagecount) { $next_link = ""; } else { $next_link = " <a href=\"http://path/to/script.cgi?reqpage=$re +qpage&page=$next_page\">". "Next" . "</a>"; } if ($pagecount > 1) { $pagelinks = $prev_link; $pageno = 0; while ($pageno < $pagecount) { $pageno++; if ($pageno == $reqpage) { $thislink = " <strong>$pageno</strong> "; } else { $thislink = " <a href=\"http://path/to/script.cgi?reqp +age=$reqpage&page=$pageno\">" . $pageno . "</a>"; } $pagelinks = $pagelinks . $thislink; } $pagelinks = $pagelinks . " " . $next_link; } else { $pagelinks = ""; } print "<br />"; print $count . "<br /><br />"; print $pagelinks . "<br />"; print "Database Results: " . $num_rows . "<br />"; print "Page " . $firstresult . " Of " . $pageno; print qq~ <br /> <br /> </body> </html>~;
In reply to Re^2: Perl Database Paging
by ironside
in thread Perl Database Paging
by ironside
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |