Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: Perl Database Paging

by graff (Chancellor)
on Apr 03, 2014 at 01:44 UTC ( #1080872=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl Database Paging
in thread Perl Database Paging

If that's the code you're trying to run, I see a few problems. I'll take it for granted that you've just edited out the declarations and assignments for the database connection strings, and when I put dummy assignments back in, the script compiles ok. Butů
  • Line 26 might cause a runtime error (param('per_page');) at best, it does nothing (except add confusion) -- have you checked the web server error log after the script runs? You might try adding use CGI::Carp 'fatalsToBrowser';
  • I'd be very suspicious/nervous about the assignment to $dsp at line 59, esp. because you're using hard-coded numbers in a substr call, right after changing all apostrophes to "%27" -- how confident are you that substr() is returning what you really want? I'll bet there's a better way to get what you want.
  • The "href" value that you assign at line 77 looks wrong -- I think you left out &page before the second '='
Eventually you'll want to switch over to using a template module - store your page layout as an HTML(ish) plain-text template file, and let the module plug in all the context-dependent variables for you. But that's a slightly bigger step for later.

Replies are listed 'Best First'.
Re^4: Perl Database Paging
by ironside (Acolyte) on Apr 03, 2014 at 22:43 UTC

    Problem solved! Another perl monk was able to help. It turns out the links were the problem. Here is the code that worked:

    # page links my $pagelinks; if ($reqpage > 1){ my $prev_page = $reqpage - 1; $pagelinks .= qq! <a href="?reqpage=$prev_page"> Previous </a> !; } for my $pageno (1..$pagecount){ if ($pageno == $reqpage){ $pagelinks .= qq! <strong>$pageno</strong>!; } else { $pagelinks .= qq! <a href="?reqpage=$pageno"> $pageno </a> !; } } if ($reqpage < $pagecount){ my $next_page = $reqpage + 1; $pagelinks .= qq! <a href="?reqpage=$next_page"> Next </a> !; }

    Thanks for your input. Much appreciated

Re^4: Perl Database Paging
by ironside (Acolyte) on Apr 03, 2014 at 04:23 UTC

    Thank you for taking the time to help me with this problem. I did edit out the db connection info. Connecting and outputting the first page of results works fine.
    I added line 26 when I was playing around with the values in the links. I have a feeling that's where the problem may be.
    Line 77 was syntax error I missed when changing the link back to how it was originally.
    On line 59 I have to remove all apostrophes from the name and replace them with "%27" so that it works in a link. I'll look into if there is a better way to do this.
    I have checked the error log and there was one minor error that I fixed, but it didn't fix the problem.
    I use Template Toolkit for storing my page layout, but right now I'm just trying to get paging working.
    Do you think it's possible why the links are working is because of the values I put after the question mark in the url?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080872]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-06-20 11:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.