maicon1121 has asked for the wisdom of the Perl Monks concerning the following question:

Good afternoon. Would you like a tutorial or code, to make a paging in perl and mysql. Thank you.

  • Comment on How to do Pagination With Perl and mySQL

Replies are listed 'Best First'.
Re: How to do Pagination With Perl and mySQL
by Your Mother (Archbishop) on Apr 30, 2012 at 19:09 UTC

    This is not a tutorial but the way I would recommend doing it; from DBIx::Class::Manual::Cookbook which is part of DBIx::Class-

    my $rs = $schema->resultset('Artist')->search( undef, { page => 1, # page to return (defaults to 1) rows => 10, # number of results per page }, ); return $rs->all(); # all records for page 1 return $rs->page(2); # records for page 2

    Probably most of the monks here who do webdev have written paging code from scratch at least once. It's not particularly hard but it *is* messy with a lot of off-by-one accounting and tracking of parameters. The paging code used above -- which uses Data::Page -- gives you a clean interface through the mess.

    DBIx::Class has a steep learning curve. You have to decide if it's worth it but while making the decision in the midst of painful first attempts keep in mind that without some kind of formal framework or rigor in the code, you are highly likely to get insecure DB interactions and rewrite things that will be extremely difficult and time-consuming for a beginner that are simple functions/methods in DBIC, etc. DBIC has a somewhat rough talking IRC channel but they do give expert help for free.

Re: How to do Pagination With Perl and mySQL
by marto (Cardinal) on Apr 30, 2012 at 17:20 UTC

    If you're offering to post a Perl/MySQL tutorial I suggest you take a look at the advice described in tutorials, posting it in the Meditations section first (with "RFC" in the title). See also the existing Database Programming tutorials. Thanks.

    Update: Belay that moderation, it's a SoPW post after all.

      Hello again, good afternoon. I think I just confused things with my terrible English. The truth is that I'm looking for a tutorial on how to create paging perl / mysql. If you have any material that could help me, would greatly appreciate it. Thank you.

        The trick is putting "LIMIT 10 OFFSET 20" to the end of your queries. The first number will be how many items per page, and the second one is how many items to skip (i.e. pages * items_per_page)