NEWS: 0 balance card credit transfer ukà?? à?? Gas credit card Debt consolidation credit counseling Credit card bad credit ok Balance card credit interest low transfer California home loan manufactured California home loan mortgage refinancing Business credit free report! Acs loan services student Bad credit car loan dallas: Bad card credit credit those Loan for people with bad credit, Business credit check Debt consolidation home loan? Citibank credit card Christian credit counseling san antonio Student balance transfer credit card Free bad credit personal loan: Credit card services for business Bad credit financing home loan Free debt consolidation service Capital one visa credit card Apply card credit macys Home equity loan montana: Bad credit student loan Accept business card credit small Debt help loan student Card consolidation credit debt unsecured Adjustable home loan mortgage rate Online business credit card deal Fix credit score Credit debt consolidation Credit free instant report Best mileage credit card Secured credit card for bad credit Bad credit cash advance. Low interest rate credit card California home loan purchase Consolidation debt information Increasing credit score? Short term personal loan Card consolidation credit debt loan relief Va home loan interest rate Advance bad cash credit loan? Bad credit mobile home loan Best equity home loan quote Get credit card numbers Bad credit unsecured loan. Credit repair software free Guaranteed bad credit personal loan! Consumer credit counseling service inc Card credit machine processing wireless Bank home equity loan rate Student loan people? Calculator card consolidation debt credit Download free music no credit card required! Bad credit easy personnel loan Free 3 bureau credit report and score California equity home in loan Card credit login mbna Fitch credit rating Bad credit fix Va home equity loan Credit letter repair report! Fix a bad credit report Fix bad credit: Home equity loan bankruptcy Equity florida home loan Bad credit repair service Credit report repair canada Card credit merchant processing service Best credit score American debt consolidation Business card consolidation credit 0 12 balance card credit month transfer à?? Free credit score no credit card needed! Card credit debt help online Accept credit card by phone California home loan rate Credit or bankruptcy counseling! Credit card special offer Small personal loan bad credit: Consolidation credit Mbna credit card company Credit free report service Card credit unsecured Best low interest credit card Find my credit score Process credit card online Consumer credit bureau Visa credit card fraud Bad credit loan canada Free credit check no credit card needed Home equity loan information: Hawaiian airline credit card Paying off credit card debt, Free credit score no credit card Interest only home equity loan Apply card credit egg uk Card chase credit na: Free instant credit card approval Home equity loan online. Credit card no checking account Card chase credit payment Unsecured credit card offer Credit card debt relief Shell oil credit card Bad credit loan mortgage va, Secured platinum credit card Bad consolidation credit debt loan! Consolidate government loan student Consumer counseling credit services Capital one credit card canada Credit history repair report Banks who offer secured credit card Credit debt consolidation: Colorado home mortgage loan company Military bad credit personal loan: America bank card credit mbna Card college credit debt statist student Home interest loan rate Bad credit loan mortgage uk Bad credit mortgage repair Home owner loan! En language loan payday Commerce bank credit card Card credit fixed interest low rate Application loan student Home equity mortgage refinance loan Company credit card policy Finance credit debt Cheap credit card deal Online credit card service Reward 660 visa credit card? Home equity loan comparison Application california home mortgage loan Credit free no obligation report Student loan debt consolidation, Aspire visa credit card First premier credit card login Free credit card machine Colorado debt consolidation loan! Ways to increase your credit score 0 balance transfer credit card Bad credit mortgage refinance Bad credit home mortgage loan No equity debt consolidation loan Aspire visa credit card Apply loan student Christian counseling credit houston Card credit online payment shell American card com credit express Card credit uk unsecured Hsbc credit card payment Credit report repair canada California credit free report? Instant credit card processing Colorado home mortgage loan company Calculator home loan mortgage refinance Lower credit card debt Card credit online payment Home equity loan poor credit Company consolidation loan student Your own credit repair business Credit card phone numbers Free web cam no credit card Credit card processing on line Federal student loan repayment Free credit report from government Bad credit repair Card consolidation credit debt program.com Georgia home loan refinance Shell credit card company Free debt consolidation program! Home loan orange county Advantage credit report triple Credit card transaction processing Annual credit report trans union Consolidation credit debt poor Instant approval 0 credit card Ecommerce accept credit card Shell credit card account online Chase credit card bill pay Home equity loan minnesota! Credit card high limit instant approval Ics payday loan Mortgage loan refinance and debt consolidation Credit card processing on line 1 3 credit in report score International loan student Mbna credit card company Free credit check no credit card needed Aspire credit card payment Guaranteed no fax payday loan! Card chase credit online payment Iowa student loan liquidity corp Beacon credit free report score Prepaid credit debit card Credit free it repair yourself Marriott reward credit card. Equity hawaii home loan rate Federal home improvement loan Free personal credit report Card college credit Guaranteed loan online personal Free debt consolidation company Student loan debt consolidation Equity home loan minnesota rate 0 advance card cash credit Debt consolidation loan bank, Bad credit report repair Home equity loan work Card credit credit free no report Cash advance payday loan Alternative student loan for bad credit Bank card services credit card Home equity loan ohio Bad credit new car loan. Credit free ohio report Card debt consolidation Bad card credit secured Bureau credit free report Credit experian free report Debt management credit counseling corporation Online credit repair Card credit interest low rate Consolidation counseling credit debt service First national bank credit card American airline credit card Debt consolidation services. California home loan rosa santa Copy credit free instant report, Agency credit report Card consolidation credit debt services? Online credit card transactions Orange county home equity loan Credit card application online Application card credit sears usa Accelerated debt consolidation Payday loan no faxing required: Bad college credit loan student Non profit debt consolidation Instant credit card application Accept credit card online merchant account Bad business credit en language loan Credit card debt after death! Online credit card processor Business credit card with reward Bad credit government loan mortgage Build credit score Nevada bad credit mortgage Prepaid credit card orchard bank Debt consolidation home equity loan Corporation loan sc student? Advance cash loan payday quick Private loan for a student with bad credit Credit equifax read report Alternative consolidation loan student Card credit credit free report Consolidation federal loan program student. Card credit minimum payment Personal loan to consolidate debt Credit counseling services of alberta Current home loan interest rate, Chase bank one credit card Debt consolidation online quote, Secured credit card high limit First premier bank credit card Debt consolidation counseling services Ohio bad credit home loan 3bureau online credit report Best us credit card deal, Consumer credit counseling of atlanta Federal student loan payment? Home loan for home improvement 200 loan no payday telecheck teletrak! Credit card for student with bad credit Free debt consolidation services: Bad credit lo personal signature Free experian credit score and report, Bad credit car loan Wal mart credit card application California home loan mortgage va Fast loan online payday Student credit card canada Card credit search uk Christy canyon on video no credit card Check credit report rating Loan mae sallie signature student Easy home equity loan Credit and debit card processing Personal loan quote. Credit card debt law Pay off credit card debt Bad credit 2nd mortgage Credit card debt consolidation oregon Payday cash loan Card credit internet payment processing: Compare credit card offer Pennsylvania home equity loan rate Low credit score loan Bad credit home loan washington? Credit report Hsbc rs credit card! Christian consolidation debt Credit card instant credit, Computer financing bad credit Student credit card online Credit card rate uk Business credit card with no personal guarantee: Credit card consolidation best deal Interest loan low personal rate Consumer credit counselor Associate student credit card, Christian credit counseling services Card credit online service Advance america payday loan Free nonprofit debt consolidation quote Citi financial credit card Countrywide home inc loan Credit rating correction Card consolidation credit debt unsecured Bad credit first mortgage Bad credit rv loan Approval card credit instant visa Center loan national service student Credit free obtain online report Worst credit card company Delaware home improvement loan Business credit report repair Bad debt consolidation loan Home loan owner personal secured Loan online student Family credit counseling corporation Credit federal free law report I have bad credit need a loan Personal loan for very bad credit Improve credit score. Low interest rate visa credit card Uk credit card. Credit card uk high risk Home loan mortgage rate quote! Credit experian report score Wal mart discover credit card Free credit repair letter Bad credit guaranteed home loan Debt consolidation loan for home owner 0 interest credit card application Canadian credit rating Consolidate consolidation counseling credit debt debt Gm master card credit card California home equity loan rate: Federal home improvement loan program Card consolidation credit debt oregon Accept card credit payment processing Great lake student loan consolidation Instant approval credit card application Bank federal home loan seattle Debt consolidation affiliate program Canadian prepaid credit card, 0 finance credit card Apply card credit online uk Card credit free report Military debt consolidation loan Bad credit computer loan Excessive credit card debt, Direct student loan consolidation Bad credit loan mortgage very: Bad credit history credit card Com credit report Boost credit score Consumer credit card debt Credit repair info Low rate credit card, Federal student loan information Free equifax credit report Online credit card application Bad credit mortgage wisconsin People with bad credit Bad credit home loan california Instant credit card number Approval canada card credit instant Credit card deal 0 Bad card credit gas California home loan mortgage second southern Personal loan canada San diego home equity loan Consumer counseling credit inc service! 0 credit card Mortgage vs home equity loan Capital one student credit card Low credit score loan! Equity florida home loan New home purchase loan Cheap credit card company Access card com credit mbna Instant online payday loan Debt consolidation loan online Consolidation credit debt rating Debt consolidation agency! Free experian credit score Bad credit home mortgage loan quote California bad credit loan Check credit free online report Free credit report with 3 score Bad credit car loan chicago. No credit card required porn Acs loan payment student Apply credit card on line Kansas city home equity loan! Home loan mortgage rate refinance Business card credit processing small Credit fico free report score Credit card business travel, Consolidation credit debt 800 credit card debt? Loan pay student Free credit report no credit card, Card consolidation credit debt Bad credit equity home loan no Credit counseling debt management agency Debt consolidation home mortgage loan Card card credit jc master penney reward Bank of america credit card application Bad credit mortgage loan new jersey Copy credit free report Instant approval credit card Card credit online payment: Bad credit fast cash loan Credit card help Citibank credit card malaysia Guaranteed online personal loan, Card credit unsecured visa Chase secured credit card: Non profit debt consolidation service Bankruptcy home improvement loan Get credit card with no credit Quick bad credit loan Unsecured personal loan online Free cell phone no credit card needed Card company consolidation credit debt Us bank credit card Credit debt consolidation Budget credit and counseling Free credit report com Prepaid student credit card Refinance car loan bad credit Bad credit credit card guaranteed approval where Citibank credit card philippine Unsecured credit card. Best gas reward credit card Chicago counseling credit, Card credit interest low offer Punishment for credit card fraud American express student credit card Card chase credit customer service Aspire credit card company Bad credit home loan mortgage, Debt consolidation home loan Debt consolidation mortgage uk Article credit card debt Austin christian counseling credit, Check credit rating Credit card online Debt consolidation loan rate Alternative loan student Credit card machine retail Balance card credit free transfer! 3 bureau credit score Forgiveness loan program student Fixed rate home loan America bank loan student Bad credit home mortgage refinance loan Christian consumer credit counseling Accepting credit card online Federal student loan consolidation Bad canada card credit credit Advance cash loan military payday Alternative student loan for bad credit Instant online credit report, Bad credit start up business loan Free trans union credit report Personal loan application Home equity loan tax Balance best card credit transfer Apply bank bank card credit credit online orchard orchard New jersey home equity loan Shell credit card company: Texas home equity loan refinancing Approval card credit guaranteed unsecured Citibank loan student Auto bad california credit loan Reduce credit card debt Personal loan lender Home loan rate in california Capital card com credit one Cash loan payday quick Bad card credit Beacon credit report score No credit card required credit report? Card consolidation credit debt Buyer california first home loan time? Advance cash loan online payday Get free porn no credit card Credit repair tip Legal credit repair Capital one bank credit card Government home improvement grants loan How to get a home loan with bad credit Canadian business credit card? Florida home loan refinance Florida home loan refinance Free annual credit report with equifax Bad credit equity home mortgage No credit card xxx Credit equifax report trw, Should i consolidate my student loan Default on payday loan Aspire credit card customer service Texas va home loan California credit free report Apply card credit egg uk? What does your credit score mean Consumer credit counseling debt consolidation National student loan canada Accepting credit card online Consolidation debt link suggest Free credit rating Bad credit home mortgage loan quote Information loan student! Wal mart credit card Atlanta debt consolidation loan Credit repair scams Trans union credit report agency Experian credit report bureau North carolina home equity loan, Bad card credit credit visa Bank card county credit monterey After bankruptcy equity home loan Wireless credit card reader? California equity home loan mortgage second Calculator card consolidation credit debt? Equity home interest loan only Bad credit houston mortgage texas. Credit repair advice Instant credit card approval with no credit Home loan for people with bad credit Add consolidation debt link Free experian credit score and report Good credit rating score! Fix your credit report Bad credit payday loan Unsecured business loan bad credit Countrywide home loan payment Credit card bad credit ok Guaranteed high risk personal loan Credit card debt bankruptcy Offshore secured credit card: Sears credit card application Card consolidation credit debt free Free credit report from trans union Colorado home loan mortgage rate Georgia home loan Credit card account online. Legal credit repair Cfs loan student Cash advance loan payday internet No limit credit card Home loan mortgage new quote Free uk online credit report New mexico home loan Adjustable home loan mortgage rate? Financing florida home loan High risk unsecured personal loan: Student credit card debt Free credit repair advice Free sex movie no credit card Direct merchant credit card: Advice blog consolidation debt Apply for jc penney credit card: Bad credit home loan mortgage se Free credit score repair: Wireless credit card terminal Bad credit florida in loan mortgage Nonprofit debt consolidation Bad credit credit card uk Equity home loan mortgage rate second Capital one credit card login, Consolidating credit card debt Improve credit score fast? Apply for a credit card canada Capital one small business credit card Debt consolidation plan Uk visa credit card. Credit card Apply for low rate credit card International loan student Reduce credit card debt: Interest loan low personal rate Consolidation defaulted student loan

Something Metaphorical

 

PaginateIt - A PHP Pagination Class

Posted in General, Goodies by Brady on the July 8th, 2005

After coding pagination functionality into a million different sites and wasting too much time every time, I decided to give OOP a shot. I’ve used this class in one site already, but haven’t tested it extensively, so there may still be some bugs.

I also used this opportunity to check out different software licenses and settled on The MIT License as it provided more flexibility. I checked out the GPL that I’ve heard so much about, but I thought it to be too restrictive for this project. This is being provided as is for whatever use anyone may want it, commercial or otherwise, under the condition that my copyright stays intact. I’d like a little credit :)

I had inline documents within the class, but I forgot to save and I don’t feel like going back and writing them again at the moment. So if you want to know what something does, just ask me. The Readme documents the methods and usage.

Go ahead and leave feedback and comments about anything (licenses, documentation, coding style/preferences, etc). I’d especially like to know if anyone finds this useful. If you need any support, don’t be afraid to ask.

PaginateIt.zip - contains readme and source file

Example - A working example of PaginateIt’s output
PaginateIt.phps - Source
Readme.doc - Documentation, usage, and licensing information

128 Responses to 'PaginateIt - A PHP Pagination Class'

Subscribe to comments with RSS or TrackBack to 'PaginateIt - A PHP Pagination Class'.


  1. on July 9th, 2005 at 3:19 pm

    […] pretty neat pagination script for anyone to use on their website or blog. Check it out at PaginateIt. I know firsthand that he’s put a lot of work into it, but I told him he s […]

  2. adam said,

    on July 13th, 2005 at 9:09 am

    cheers for this. i was in a terrible hurry (as always) to get some quick, modern pagination into a site, and this completely came through.

  3. Brady said,

    on July 13th, 2005 at 4:20 pm

    Awesome, I’m glad you found it useful. Was there anything you didn’t like about it, or you thought that it could use? Did the readme cover everything pretty good?

    I’ll prolly add different tidbits and scripts like this every once in awhile when I need to write one, so check back every now and then and thanks for the feedback.

  4. adam said,

    on July 15th, 2005 at 8:35 pm

    yeah the readme was fine by and large. i had it going in a few minutes.

    the thing i really liked though was that it’s abstracted from the actual request : most pagination makes you structure your query around it, while this offered the lovely lil limit limit clause you could pop right in your query.

    one thing of note, i noticed your back and next links jump to the next “group” of pages, rather than just a single page. for the default behavior, it might be good to have those links either say something like “next 10″ (or whatever).

    trivial, trivial usability detail really, and since you can change it without even altering the class anyway i wasn’t particularly fussed either way.

    {bookmarked} :]

  5. adam said,

    on July 15th, 2005 at 8:38 pm

    oh, incidently it seems to do fine on a site with over 5,000 products, so that’s probably a reasonable stress test, heh.

  6. jen said,

    on July 21st, 2005 at 9:56 pm

    Thank you for the wonderful script. I have a few comments:

    1. I added this function because I think it lacks your get functions:
    function GetStartIndex(){
    return ($this->currentPage * $this->itemsPerPage - $this->itemsPerPage);
    }

    2. I think there is a bug on your script. I have these:
    $PaginateIt =& new PaginateIt();
    $PaginateIt->SetItemsPerPage(5);
    $PaginateIt->SetItemCount(19);
    $PaginateIt->SetLinksFormat( ‘>’ );
    echo $PaginateIt->GetPageLinks();

    It then displays: 1 | 2 | 3 | 4
    But when I try to click the “4″ link, it displays: 0 | 1 | 2 | 3 | 4

  7. Brady said,

    on July 22nd, 2005 at 11:57 pm

    Cool, thanks for the feedback Adam. The SQL limit is what was most useful for me, so I included it. As for jumping through groups of links, I don’t particularly like it, but it seems like it’s the most practical approach. You’re right about the usability issue, though, I was just looking for a good way to word it.

    Yep, that’s a bug, Jen. Thanks for pointing it out. I believe it’s fixed now and hopefully there’s not anymore. But I got to upgrade my version to 1.0.1, sweeeettt =P I’ll give you credit if I ever add a changelog or somethin. I thought about adding the Start Index, but didn’t find it useful for me, although I shoulda known someone else could have used it. I’ll add it when I find more time. Thanks for the feedback, and I’m glad you found it useful.

  8. Jasper said,

    on July 23rd, 2005 at 8:54 pm

    Wow, you are a total resource now! That is awesome!

  9. Adam Gedde said,

    on July 26th, 2005 at 10:52 am

    Brady:

    I have to tell you - this script was pretty easy to use!

    I’d been using a different paging class that caused some issues with more advanced SQL statements. I didn’t have the time to debug the paging class myself, so I turned to Google and found your script. After looking at the code and the API, I managed to implement it in about 15 minutes.

    Excellent work.

    Adam Gedde

  10. adam said,

    on August 7th, 2005 at 2:09 pm

    upgraded. still waitin for a new post to read :P

  11. admX said,

    on August 8th, 2005 at 9:45 am

    sorry, but I don’t speak english well.

    Is it error here?

    « Back 1… 2 3 4 5 6 …100 Next »

  12. admX said,

    on August 8th, 2005 at 9:47 am

    aaa

    I’m add new method

    function GetLimit(){
    return ‘ LIMIT ‘.($this->currentPage-1)*$this->itemsPerPage.’, ‘.$this->itemsPerPage;
    }

    for query to MySQL

  13. admX said,

    on August 9th, 2005 at 8:34 am

    upsss soryy my mistake

  14. adam said,

    on August 12th, 2005 at 12:12 am

    odd, for some reason i’m getting a potentially weird result with the new version while trying to impliment it into my homebrew php bugtracking system. it might just be my calling class functions in an inproper order perhaps…
    //snip
    $paginate = new PaginateIt(); // prep pagination
    $paginate->SetItemsPerPage($limit);
    $queryLIMIT = $paginate->GetSqlLimit();
    $paginate->SetQueryString("$s_PersistentVars");
    $connection->queryString("SELECT n_ID FROM $table $WHEREClause");
    $connection->getRows($connection->result);
    $numberOfRows = $connection->numrows;
    $paginate->SetItemCount($numberOfRows);
    $paginate->SetLinksFormat( 'Prev 10', ' | ', 'Next 10' );
    $pages = $paginate->GetPageCount();
    //snip

    it’s pseudo hungarian notation just without the mneumonic, so you probably get the idea.

    a few sample results of the output:

    http://www.graphicsdesign.org/paginate1.gif

    the first one prints properly as far as the numeric links and the separation character go, but the skip links don’t seem to show. i’m assuming this is because there’s less than 10 pages in the results.

    http://www.graphicsdesign.org/paginate2.gif

    but the skip links seem to return when there’s 0 results, so i’m not sure…

    is it maybe just a simple case of it not checking if there’s 0 results?

  15. Akif said,

    on August 12th, 2005 at 4:06 am

    Great and simple use class, even though for a begginer like me! You made my day thanks a lot!

  16. Brady said,

    on August 13th, 2005 at 5:35 pm

    Thanks for all the comments and feedback everyone.

    I looked into the functionality, adam, and I designed it that way for some reason, although I admit it’s kinda weird why I did it. I updated the script so that the next and back links won’t show up when there’s 0 results.

  17. Ali said,

    on August 14th, 2005 at 2:59 pm

    *starts chanting*
    Update, update!! :)

  18. Jason said,

    on August 16th, 2005 at 12:19 pm

    I got this working but not working right. Is there an actual “working” version of this class pulling data from a database?

    Thx!

  19. salto said,

    on September 5th, 2005 at 3:11 am

    Could anyone help a newbie and point me to a code example how to get this to work on a flatfile (CSV). I use fgetcsv to return the data. Thanks very much in advance!!

  20. adm said,

    on September 8th, 2005 at 6:27 am

    your script generated bad links
    look
    3
    should be
    3

    thank’s a lot

  21. adm said,

    on September 8th, 2005 at 6:28 am

    look
    index.php?nav=branza&id=1&page=3

    should be

    index.php?nav=branza&id=1&page=3

  22. Brady said,

    on September 8th, 2005 at 7:03 am

    Could you help me out a little, adm? I’m not seeing a difference between those two.

  23. adm said,

    on September 8th, 2005 at 10:47 am

    it’s not my faul, it’s faul scritp guest book on this site.

    look
    ‘index.php?nav=branza & id=1 & a m p ; page=3′

    should be

    ‘index.php?nav=branza& a m p ; id=1 & a m p ; page=3′

  24. Brady said,

    on September 8th, 2005 at 5:45 pm

    Oh, I think I gotcha, you mean it’s invalid XHTML. Well that’s no bueno, so with that I announce the release of version 1.0.3. Ohhhh, ahhhhh, heh, ok, enough of that. I fixed it up so that it spits out valid XHTML links now. Thanks for bringing that to my attention adm and sorry about the formatting problems, Wordpress does that automatically.

  25. adm said,

    on September 11th, 2005 at 3:37 pm

    Thank’s You. I’m sorry for my language;)
    I try to be better. Good luck!

    pleas remove my previous comment;)

  26. Graham said,

    on October 27th, 2005 at 10:11 am

    Brady,

    This is a great little script. Would you be able to point me in the right direction with using this with an array rather than a database?

    Thanks!

  27. Aivo Koger said,

    on October 30th, 2005 at 7:42 am

    Hello,

    First I would like to say, that you have done great job! This class is fantastic.
    But newby as I am, I have some problems. It works fine in my server as it is, but I just can’t get it to work inside my system. I want to use this script in a page ‘?id=something’ not just ‘index.php’. Can you please give a short script, how to get it work then.
    I am just getting echod nr “1″, that all, no page links, nothing :(
    I am using:

    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemsPerPage(5);
    $PaginateIt->SetQueryStringVar(’lk’); // page = lk, like ?id=1&lk=23
    $PaginateIt->SetLinksHref(’index.php’);
    $PaginateIt->SetLinksToDisplay(8);

    $total_res = mysql_num_rows($base->query(”SELECT COUNT(*) FROM table”));
    $PaginateIt->SetItemCount($total_res);
    $p = $base->query(”SELECT * FROM table ORDER BY id DESC” . $PaginateIt->GetSqlLimit());

    $PaginateIt->SetLinksFormat( ‘’, ‘ ‘, ‘’ );

    echo $PaginateIt->GetPageLinks();

    Thanks for any help…

  28. Aivo Koger said,

    on October 30th, 2005 at 7:46 am

    Note:

    $PaginateIt->SetLinksFormat( ‘image1’, ‘spacer‘, ‘image2’ ); - it had HTML code images inside, but your guestbook deleted them :)

  29. Brady said,

    on October 31st, 2005 at 11:48 pm

    I updated the class so that it now supports arrays. Just pass an array like this:
    $newArray = $PaginateIt->GetCurrentCollection($array);
    This will return an array containing only the elements that should be displayed on the current page.

  30. somedude said,

    on November 16th, 2005 at 10:16 pm

    For Postgres:

    function GetSqlLimit(){ return ‘ OFFSET ‘.($this->currentPage * $this->itemsPerPage - $this->itemsPerPage).’ LIMIT ‘.$this->itemsPerPage;

  31. tigglet said,

    on November 17th, 2005 at 9:10 am

    Thanks for the PaginateIt class! Very useful! I hacked the class a little so that the NEXT/PREV jumps to the next and previous pages respectively, while the arrows jump to the next sets. Other than that, I didn’t have to change a thing. Very cool class that saved me a ton of time! Thanks again!

  32. adm said,

    on November 23rd, 2005 at 11:24 am

    look:
    http://www.zundam.net/paginate_wrong.gif
    something wrong?
    ???

  33. ruvan said,

    on November 24th, 2005 at 1:31 am

    When item count is set to something like 150 it just displays 15 links. Any body know why?

    Thanx in advance.

  34. Brady said,

    on November 24th, 2005 at 1:43 am

    adm: I don’t see anything wrong with that. Could you provide more details?

    ruvan: You can set the number of links to display using the SetLinksToDisplay() method.

  35. ruvan said,

    on November 24th, 2005 at 10:22 am

    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemCount(150);
    echo $PaginateIt->GetPageLinks();

    this just displays 15 links. i mean i could only browse just 15 links(not per page. All)

  36. adm said,

    on November 24th, 2005 at 11:54 am

    1… 2 3 4 5 |6| 7 8 9 …20

    should by
    1 2 3 4 5 |6| 7 8 9 …20

  37. Oglikn said,

    on November 26th, 2005 at 7:30 pm

    Thanks so much for a great piece of work. With a few modifications, it does exactly what I wanted and saved me a lot of work.

  38. Henker said,

    on December 3rd, 2005 at 2:29 pm

    Hi, I have this script that checks a mailbox but don t know how to paginate the results using the PaginateIt class, help me please. Thanks

    The script:
    $mbox = imap_open(”{localhost:143}”, “username”, “password”)
    or die(”can’t connect: ” . imap_last_error());
    $MC=imap_check($mbox);
    $MN=$MC->Nmsgs;
    $overview=imap_fetch_overview($mbox,”1:$MN”,0);
    if (is_array($overview)) {
    foreach ($overview as $val) {
    echo “$val->msgno - $val->date - $val->subject\n “;
    }
    }
    imap_close($mbox);

  39. admx said,

    on December 6th, 2005 at 12:57 pm

    look
    http://www.krakow.targi.eco.pl/index.php?nav=opcja&id=7&page=7

    Is it wrong or normal situation?

    1… | 2 | 3 | 4 | 5

  40. Brady said,

    on December 6th, 2005 at 1:24 pm

    That’s actually the correct functionality, admx, but I can see how it might be confusing. It shouldn’t be too hard to change, but it’s not necesarily wrong, so I’ll leave it be for now.

    For anyone interested, here’s the reply I sent to Henker. I haven’t tested it, but this is how it should work theoretically.

    <?php

    include(‘PaginateIt.php’); // set this to the location of the PaginateIt class

    $mbox = imap_open(”{localhost:143}”, “username”, “password”) or die(”can’t connect: ” . imap_last_error());
    $MC=imap_check($mbox);
    $MN=$MC->Nmsgs;
    $overview=imap_fetch_overview($mbox,”1:$MN”,0);
    if (is_array($overview)) {
    $PaginateIt->SetItemsPerPage(10); // change this to the number of items you want to show

    $PaginateIt->SetItemCount(count($overview));

    $overview = $PaginateIt->GetCurrentCollection($overview));

    foreach ($overview as $val) {
    echo “$val->msgno - $val->date - $val->subject\n “;
    }
    }
    imap_close($mbox);

    echo $PaginateIt->GetPageLinks();

    ?>

  41. Vikash said,

    on December 7th, 2005 at 7:57 pm

    Hi Brody,

    i have been trying to use your pagination script to do ldap result search, any help/sample scripts will be greatly appreciated.

    cheers…

  42. Taylor said,

    on January 9th, 2006 at 6:37 pm

    Brody,

    Can you provide an example for pagination a MySQL result set? Do I need 2 queryies? Here is what I have now.

    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemsPerPage(25);

    $categories = mysql_query(”SELECT id FROM table WHERE id = ‘$id’”);
    $PaginateIt->SetItemCount(mysql_num_rows($categories));
    $categories = mysql_query(”SELECT id FROM table WHERE id = ‘$id’” . $PaginateIt->GetSqlLimit());

    Then I print my results here…

    echo $PaginateIt->GetPageLinks();

    Any help is appreciated!

  43. Kevin J. Garriott said,

    on January 12th, 2006 at 11:17 am

    Hey Brady,

    This class is saving me tons of work! However, I’m having an issue with a customization I’m working on. I created a select box that allows users to change the # of records per page, it works great with the current page they are on, but the problem arises when they click one of the page links, i.e. page 2.

    When they click the link, it resets the data grid back to the original value of “SetItemsPerPage()”. For example, say it is set to 10 by default. When they change it, the records update from only 10 on the page to what they choose and the list and the number of page links adjusts accordingly. If they want to go to page 2, when they click page 2 it resets the data grid back to 10 records per page.

    Is this something that can be manipulated within the class to read the value of SetItemsPerPage() for each page in the set, or do I need to take another approach?

    Here’s a brief excerpt of my code:

    $PaginateIt =& new PaginateIt();
    if(isset($_POST[’calls’])){
    $PaginateIt->SetItemsPerPage($_POST[’calls’]);
    }else{
    $PaginateIt->SetItemsPerPage(10);
    }
    $PaginateIt->SetLinksToDisplay(3);
    $items = mysql_query(”…sql statement here…”, $db);
    $tItems = mysql_num_rows($items);
    $PaginateIt->SetItemCount($tItems);
    $PaginateIt->SetLinksFormat( ‘>’ );

    Thanks!

    –kg


  44. on January 24th, 2006 at 11:38 am

    […] y: archie

    So I’m now using an RSS parsing class and a PHP Pagination class to make the galleries work. The more I try to get working, the more th […]

  45. Chris said,

    on January 30th, 2006 at 4:27 pm

    // Example Working
    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemsPerPage(1);
    $PaginateIt->SetLinksToDisplay(5);

    // first query, see how many results are actually in the table
    $query = mysql_query(”SELECT * FROM table”);
    $result = mysql_num_rows($query);
    $PaginateIt->SetItemCount($result);

    // second query, find only the relevant results
    $sql = “SELECT * FROM table ” . $PaginateIt->GetSqlLimit();
    $query = mysql_query($sql);

    // loop through second query
    while($row = mysql_fetch_array($query))
    {
    echo “” . $row[’title’] . “” ;
    }

    $PaginateIt->SetLinksFormat(” ” );
    echo $PaginateIt->GetPageLinks();


  46. on February 10th, 2006 at 4:46 am

    […] tats d’un moteur de recherche. AprĂšs quelques recherches Google, j’ai trouvĂ© PaginateIt qui me convient parfaitement. Cette petite librairie fournit une classe bien do […]


  47. on February 16th, 2006 at 4:19 pm

    […]
    Something Metaphorical » PaginateIt - A PHP Pagination Class Something Metaphorical » PaginateIt - A PHP Pagination Class This […]


  48. on February 19th, 2006 at 2:18 pm

    Congrats for this very usefull class: it took me 15mn to integrate it in a working page with awfully implemented pagination.
    Lucky me that thought, at last, searching google before reinventing the wheel it:)

    Cheers!

  49. Sen said,

    on March 20th, 2006 at 12:32 am

    I have problem in passing the query string from page 1 to the next page.
    My query string consist of dynamic “where” condition, and the values are passed from “search feature”.
    The PaginateIt itself works very well, but as I try to access the next page, the “where” value turned back to null.

    Can anybody help me? Thanks a lot.

    Code:

    List Rajut

    0 AND statusDEL=’1′”;

    if ($tahun_from!=”"){
    if($bulan_from!=”"){
    if($tanggal_from!=”"){
    if($tahun_until!=”"){
    if($bulan_until!=”"){
    if($tanggal_until!=”"){
    $date_from=$tahun_from.$bulan_from.$tanggal_from;
    $date_until=$tahun_until.$bulan_until.$tanggal_until;
    if($date_untilSetQueryString($query);

    $rajuts=mysql_query($query);
    if (!$rajuts){
    echo(”");
    echo(”Error retrieving rajut’s production data from database”.
    “Error:”.mysql_error());
    exit();
    }

    $result = mysql_num_rows($rajuts);
    $PaginateIt->SetItemCount($result);

    echo $PaginateIt->GetPageLinks();

    $rajuts=mysql_query($query.$PaginateIt->GetSqlLimit());

    while($rajut=mysql_fetch_array($rajuts)){
    ……}
    ?>

  50. Sen said,

    on March 20th, 2006 at 12:36 am

    I think my code was not complete uploaded :(
    But btw. can anyone give me example how to pass query string generated from a “search feature” so that every pages displayed will have same query string.

    Thx

  51. Brady said,

    on March 21st, 2006 at 9:51 pm

    Hello Sen,

    The script should automatically pick up the querystring if it’s present when the PaginateIt class is called. Otherwise, you can use the SetQueryString method to add variables to the querystring before you call GetPageLinks.

    Example:
    $PaginateIt->SetQueryString(’?search=value&var2=value2&etc=more’);

    Let me know if that answers your question.

  52. Sen said,

    on March 22nd, 2006 at 6:21 am

    Hallo brady,

    thanks, it could solve the problem.
    But I got another probem now :(

    I made a PHP web site with search function:

    $select = “SELECT *”;
    $from = ” FROM data_one”;
    $where = ” WHERE ID>0″;

    //here comes the next condition inserted via the form and my problem starts here:

    if($value!=”"){
    $where .= “AND constraint LIKE ‘%$value%’”;
    }

    $query = $select $from $where;
    $temps = mysql_query($query);
    while($t = mysql_fetch_array($temps)){
    …. //code
    }

    This page works fine combined with the PaginateIt() but as I enter number into the constraint, such as 5000100… the querystring was only correct at the first page.
    I try to echo the querystring at the other page… and the result, it changed from LIKE ‘%5000100′% into LIKE P00100%’.
    Why? Any Idea?

    My second problem still realted with the form’s value: I try to Set the querystring using the method you gave, but you see my code… I must set the dynamic “where clause” inside my code, and if I try this

    $PaginateIt->SetQueryString(’?where=$where’);

    and I retrieve the value by using GET :

    $where=$_GET[’where’];

    it always returns the empty form, because the form’s value becomes empty at the next page. I think, because It is always re-set by the SetQueryString method before I can use the where value I need (which I set at the first page).
    Maybe you can suggest any solution?

    Thanks a lot Brady

    Sen

  53. Brady said,

    on March 22nd, 2006 at 10:10 pm

    Hmm, I can’t tell what your problem is from that code, but here’s a few suggestions.

    You should never pass anything through the querystring that you’re going to use in a SQL statement, it’s a major security flaw. Someone could easily drop your database if you use that method. Also, all data from the query string should be checked and verified before you use it in your code.

    I simplified the code a little. I’m assuming you have a page with a search form and when someone clicks ‘Search’, it goes to the search results. If that’s the case, here’s how you should set the querystring.

    if(!isset($_GET[’value’])){
    $PaginateIt->SetQueryString(’value=whatever’);
    }

    // if ‘value’ is set in the querystring, convert applicable characters to htmlentities; this is for security
    $value = (isset($_GET[’value’])) ? htmlentities($_GET[’value’]) : ‘’;

    $sql = ‘SELECT * FROM data_one WHERE ID>0′;
    if(!empty($value)){
    $sql .= ” AND constraint LIKE ‘%$value%’”;
    }

    $query = mysql_query($sql);
    while($t = mysql_fetch_array($query)){
    // code
    }

    I hope that helps.

  54. Lobos said,

    on March 31st, 2006 at 9:52 am

    Hi Brady,

    Great class man!

    I have implemented it as a postnuke module, purely as an example for people to integrate the class with their postnuke modules.

    Download here:

    http://www.postnuke.co.nz/downloads/paginate.zip

    Once again thanks for your work.

    -Lobos

  55. adm said,

    on April 2nd, 2006 at 6:03 am

    Hi Brady,
    I found new error

    http://zundam.net/pagination_error1.png

  56. Daniel said,

    on April 14th, 2006 at 3:26 pm

    I’ve set $PaginateIt->SetLinksToDisplay(10);
    First display is 1-2-3-4-5-6-7-8
    If I go to page 8 pages # links are “-1, 0,1,….8″
    The same is when I go to page 7.
    It seems like the class forces to display 10 numbers.

  57. Brady said,

    on April 14th, 2006 at 5:39 pm

    Thanks for the comments, Lobo, I’m glad you found it useful.

    adm and Daniel, I believe you’re both experiencing the same bug. I noticed the bug awhile ago, but didn’t have time to update. I went ahead and released an updated version, so using that should fix ya’lls problem.

  58. Sabin said,

    on April 28th, 2006 at 5:57 pm

    Big B-

    I am having a bit of a problem getting the class to read my array (a completed search result set). Do you happen to have a walk-through or a code example for a newbie such as myself, that could show me how to get my array read?
    danke

  59. Brady said,

    on May 3rd, 2006 at 6:52 am

    Sorry about the slow response, Sabin. I’ve been away on vacation. Here’s how you’d do what you want.

    $array = range(5, 69); // some array; your search result set

    $PaginateIt =& new PaginateIt();
    $PaginateIt->SetItemCount(count($array));

    $pageArray = $PaginateIt->GetCurrentCollection($array));

    /*
    do whatever you want to display $pageArray
    */

    echo $PaginateIt->GetPageLinks();

    That should be all there is to it. You can set any other variables before you call the “GetCurrentCollection” method. Let me know if that works for you.

  60. Michael said,

    on May 21st, 2006 at 2:27 pm

    Brady, I just wanted to say thanks so much for the great script. This surely saves me a great deal of time!

  61. matthew said,

    on May 25th, 2006 at 6:27 am

    i’m confused on how this works with a sql query.

    if someone can illuminate for me — i’ve got a page with about 5000 items that need paginated.

  62. Shatabdi Bhattacharya said,

    on July 18th, 2006 at 11:02 am

    This is a real nice peace of code , a saves a lot of work for me, thanks a lot

  63. Dan said,

    on July 25th, 2006 at 11:50 am

    Wicked class :) thanks a bunch

  64. Eve said,

    on August 1st, 2006 at 4:10 pm

    It would be great if I someone could post their source code of a very basic pagination page and/or function.

    I am having trouble in that some pages do not ‘page’ when clicking on the 1, 2, 3, etc.

  65. Eve said,

    on August 7th, 2006 at 9:54 am

    How could I make this work with a dynamically generated SQL statement?

  66. Keith said,

    on August 15th, 2006 at 10:09 pm

    Hi, thanks alot for this, saved me hours

  67. adm said,

    on August 16th, 2006 at 10:59 am

    still wrong
    -1 0 1 2 3 4 5 6 7 8

  68. Brady said,

    on August 16th, 2006 at 1:11 pm

    I don’t know how you’re getting that output adm. Could you send me exactly what you’re doing?

  69. adm said,

    on August 16th, 2006 at 1:21 pm

    include(’paginate.class.php’);
    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemsPerPage(30);
    $PaginateIt->SetLinksToDisplay(10);
    $PaginateIt->SetItemCount($data[’count’]);
    $PaginateIt->SetLinksFormat(’«’,’ ‘,’»’);
    $limit = $PaginateIt->GetSqlLimit();

  70. Brady said,

    on August 16th, 2006 at 10:25 pm

    Oops, I figured out the problem. The zip file contained the fix, but the .phps source file didn’t have the fix implemented. Sorry about that, everything should be working now.

  71. adm said,

    on August 17th, 2006 at 2:31 pm

    good job:)

    my sugestion:
    change
    $this->SetQueryString($_SERVER[’QUERY_STRING’]);

    for
    if(isset($_SERVER[’QUERY_STRING’])){
    $this->SetQueryString($_SERVER[’QUERY_STRING’]);
    }else{
    $this->SetQueryString();
    }

  72. Steve Sullam said,

    on August 26th, 2006 at 2:05 pm

    First off, newbie shewbie, I’m a fucken retard.
    I am attracted to this script because I assume it takes just a little tinkering to get it to work. My setup looks like this and I get all the nice links at the bottom of the page. My problem is that I change the number SetItemsPerPage number and it continues to show all the items from the column/table regardless. The number of items per page doesn’t change.

    ?>

    SetItemsPerPage(5);
    $PaginateIt->SetItemCount(100);

    echo $PaginateIt->GetPageLinks();
    ?>

  73. Randy said,

    on August 28th, 2006 at 8:45 pm

    thx. got it to go after a bit in 21 lines of code. I wasn’t looking forward to doing this myself, so thanks again. I also had a question about outputting an array slice using the currentPage and itemsPerPage vars, so I wouldn’t have to make another sql query. With an associative array, that was too hard on my tired brain. Instead I opted for doing another sql query with the GetSqlLimit() function.


  74. on August 30th, 2006 at 11:05 am

    […] clase en PHP para paginar registros de forma sencilla y eficiente. Aqui No Comments to “PaginaciĂłn en PHP& […]

  75. Ananda said,

    on August 31st, 2006 at 7:15 am

    Great script… Iglad I found this an appriciate the work!

    I’m using codeigniter as ap-framework and uses searchengine friendly links
    like

    www.mysite.net/products/results/1

    where
    -> www.mysite.net/products/ is the pathinfo (no index.php)
    -> results the queryParameter
    -> 1 is currentPageNumber

    How I configurte PagniateIt in this environment especially how to setup the queryStr?

  76. Sayian said,

    on September 1st, 2006 at 7:16 am

    Brady,

    I’ve been using this great class for 2 years now and it has saved me a great amount of work.

    Thank you.

    You really do great work.

  77. DJ said,

    on September 22nd, 2006 at 9:16 am

    Just started using and it works really well. One problem I’m having is in my understanding…probably because my php is very poor.

    No problems at all on a standard grid, but when I apply to a search page I get problems. If i use SetQueryString hardcoded, e.g (’field2=123&field2=abc), absolutely no problem, the page paginates properly with the expected search results. Obviously, I need this to be driven by variables as input from the original search form. But as soon as try to apply a variable e.g (’field1=$xxx&field2=$yyy) I get errors as the sql query seems to fail.

    I gues I’m doing something really stupid. Does anyone know what ?

  78. jay said,

    on October 28th, 2006 at 5:09 am

    first of all thank you for a great class!! good work

    i was just having trouble with the following:

    can anybody help me change the links so that when i click next/back,
    only the page next to it should be displayed. because it jumps to the page according tho the linkstodisplay..

    thanks..

  79. Hairul Azami said,

    on January 3rd, 2007 at 8:05 pm

    I had tried

    $PaginateIt->SetQueryString(’cPub=cariDonatur&cOpt=hasilCariDonatur&operator1=$operator1&query=$query1′);

    But the result for operator1 = $operator1 and query = $query1

    By the way, here is my full code, Please tell me the lines wrong below.

    //My Full Code
    include(’inc/PaginateIt.php’);
    $PaginateIt = new PaginateIt();
    $PaginateIt->SetItemsPerPage(25);
    $PaginateIt->SetLinksToDisplay(15); // view link : nav/ page

    // first query, see how many results are actually in the table
    $QRY1 = mysql_query(”SELECT * from $tblDonatur where $operator1 like ‘%$query%’ order by nama”);
    $result = mysql_num_rows($QRY1);
    $PaginateIt->SetItemCount($result);

    // second query, find only the relevant results
    // $SQL = “SELECT * FROM com_donatur ” . $PaginateIt->GetSqlLimit();
    // $QRY2 = mysql_query($SQL);
    // loop through second query

    $JML=mysql_num_rows($QRY1);
    if($JML>0) {
    echo “Result of : ‘ $operator1 ‘ , with the key ‘ $query ‘, was $JML data.”;
    //echo ”
    //
    //”;
    //get string2 url;
    $PaginateIt->SetQueryString(’cPub=cariDonatur&cOpt=hasilCariDonatur&operator1=$operator1&query=$query1′);

    echo “Page. “; $PaginateIt->SetLinksFormat(” > “);
    echo $PaginateIt->GetPageLinks();
    echo “”;

    echo ”
    ID
    Nama
    Tempat, Tgl. Lahir
    Alamat
    Kota
    Propinsi
    Kodepos
    Telp
    Status
    BSPI“;
    echo “”;
    while($ROW = mysql_fetch_array($QRY1))
    {
    if($ROW[blnLahir]==1) { $cvtBln=”Jan”; }
    elseif($ROW[blnLahir]==2) { $cvtBln=”Feb”; }
    elseif($ROW[blnLahir]==3) { $cvtBln=”Mar”; }
    elseif($ROW[blnLahir]==4) { $cvtBln=”Apr”; }
    elseif($ROW[blnLahir]==5) { $cvtBln=”Mei”; }
    elseif($ROW[blnLahir]==6) { $cvtBln=”Jun”; }
    elseif($ROW[blnLahir]==7) { $cvtBln=”Jul”; }
    elseif($ROW[blnLahir]==8) { $cvtBln=”Agu”; }
    elseif($ROW[blnLahir]==9) { $cvtBln=”Sep”; }
    elseif($ROW[blnLahir]==10) { $cvtBln=”Okt”; }
    elseif($ROW[blnLahir]==11) { $cvtBln=”Nop”; }
    else { $cvtBln=”Des”; }
    echo ”
    “;
    userId($ROW[IDb], $ROW[IDc]);
    echo ”

    $ROW[nama]
    $ROW[tempatLahir], $ROW[tglLahir]-$cvtBln $ROW[thnLahir]
    $ROW[alamat]
    $ROW[kota]
    $ROW[propinsi]
    $ROW[kodepos]
    $ROW[telp]
    $ROW[status]
    $ROW[bspi]”;
    echo “”;
    }
    echo “”;
    $PaginateIt->SetLinksFormat(” > “);
    echo $PaginateIt->GetPageLinks();

    }
    else
    {
    echo “Tidak ditemukan Data, berdasarkan Kata Kunci ‘ $query ‘”;
    }

  80. Hairul Azami said,

    on January 3rd, 2007 at 8:07 pm

    I mean the result of string operator1 and query is still a variable, not the values. Thank you so much..

  81. Brady said,

    on January 3rd, 2007 at 9:06 pm

    Hairul, I didn’t look over your code too closely because I noticed the following and thought it might be the cause of your problems.

    $PaginateIt->SetQueryString(’cPub=cariDonatur&cOpt=hasilCariDonatur& operator1=$operator1&query=$query1â€Č);

    You have single quotes around the parameters instead of double quotes. If you’re going to embed variables inside strings in PHP, you must use double quotes. Anything inside of single quotes doesn’t get parsed by PHP and is read as a string.

    $PaginateIt->SetQueryString(cPub=cariDonatur&cOpt=hasilCariDonatur& operator1=$operator1&query=$query1);

    Let me know if that works for you.

  82. Andre said,

    on January 5th, 2007 at 9:16 pm

    I really appreciate this class!

    I am having a problem with $PaginateIt->GetPageLinks(); (where it actually spits out the linked page numbers). At the moment, no matter how many results it finds it just prints the number ‘1′ there.

    If I manually enter a different page variable in my URL it reloads the page with the appropriate rows, but still prints a ‘1′. From these other pages, the ‘1′ is a link and goes to the correct page.

    Any ideas?

  83. Egwin said,

    on February 1st, 2007 at 12:29 pm

    Hello,

    is it possible to always show the SetLinksFormat e.g. always showing the ‘

  84. Egwin said,

    on February 1st, 2007 at 12:32 pm

    Hello,

    is it possible to always show the SetLinksFormat e.g. always showing the “

  85. David said,

    on February 4th, 2007 at 2:28 pm

    Thanks for a great class, however I set it up and this is what I see:

    “Fatal error: Cannot redeclare class PaginateIt in C:\XXX\classes\PaginateIt.php on line 2″

    Any ideas? Does the class work with PHP5?

    David.

  86. Enseignement said,

    on February 6th, 2007 at 5:37 am

    What about URL rewriting ??

    How can I make this script work with url rewrited pages ?

  87. Miguel said,

    on February 13th, 2007 at 1:26 pm

    Hi, is this script support the use of next, back with the normal behavior ?

    Next goes to next page on not 10 pages after ?
    Same behavior for Back …

    By the way, howesome work :)

    thnaks


  88. on February 18th, 2007 at 6:31 pm

    […] ode examples floating about the net but not so many classes. Anyway here’s the link. http://www.bradyvercher.com/php-pagination-class.html  This entry […]

  89. glenn said,

    on March 7th, 2007 at 11:54 pm

    hello…
    I saw your code on the net and I have been trying to insert this on my query code. Can you please help me. I haven’t slept in a couple of days. here is what I have now and I want to display 25 results per page. I would really appreciate your help, Thank you in advance.

    $result = mysql_query(”SELECT * FROM listed ORDER BY SCHOOL”);
    echo ”

    School
    Title
    Edition
    Author(s)
    Price
    Email

    “;

    while($row = mysql_fetch_array($result))
    {
    echo “”;
    echo “” . $row[’School’] . “”;
    echo “” . $row[’Title’] . “”;
    echo “” . $row[’Edition’]. “”;
    echo “” . $row[’Author(s)’] . “”;
    echo “” . $row[’Price’] . “”;
    echo “” . $row[’Email’] . ““;

    echo “”;
    }
    echo “”;

    mysql_close($con);
    ?>

  90. tradingbasics said,

    on March 20th, 2007 at 8:29 am

    Can help me how to apply Paginateit to this array

    Click to see the product';

    }
    ?>

  91. Aaron said,

    on April 2nd, 2007 at 9:07 pm

    Thanks for the great script. Makes my life so much easier.

    One question as I can’t for the life of me get the Next and Previous links to show up. Just the page numbers, which work perfectly.

    Here’s my code: ($result_array is a multi dimensional array of data from MySQL)

    $pagination = new PaginateIt();
    $pagination->SetItemCount($rec_count);
    $pagination->SetItemsPerPage(10);
    $pagination->SetLinksFormat(”BACK”, ‘ | ‘, “NEXT”);
    $current_result = $pagination->GetCurrentCollection($result_array);

    echo $pagination->GetPageLinks()

    foreach($current_result as $result) {
    // Display individual record data
    }

    What am I doing wrong? It seems to happen around line 112 of your class:

    if(isset($start)){
    if($start > 1){…..

    $start is always 1 when I output it

  92. Nick said,

    on April 22nd, 2007 at 11:49 am

    I had the same issue as Aaron and Andre where the page links always display a ‘1′. The problem is that I copied Aaron’s code that he posted. to make a long explanation short, inside PaginateIt.php, the Brady is initilizing the class already as $PaginateIt = new PaginateIt();

    Aaron, remove your call to $pagination = new PaginateIt(); and call member functions like “$PaginateIt->”. Otherwise comment out the last line in PaginateIt.php where the class is initialized and call member functions using your variable like “$pagination->”.

  93. Nick said,

    on April 22nd, 2007 at 12:32 pm

    Make back button, next button display correctly and eliminate 1… 1 in the page links. Replace GetPageLinks() function with:

    function GetPageLinks(){
    $strLinks = ‘’;
    $pageCount = $this->GetPageCount();
    $queryString = $this->GetQueryString();
    $linksPad = floor($this->linksToDisplay/2);

    if($this->linksToDisplay == -1){
    $this->linksToDisplay = $pageCount;
    }
    if($pageCount == 0){
    $strLinks = ‘1′;
    }
    elseif($this->currentPage - 1 linksToDisplay + 1 == 0) || $this->linksToDisplay > $pageCount){
    $start = 1;
    }
    elseif($pageCount - $this->currentPage linksToDisplay + 1;
    }
    else {
    $start = $this->currentPage - $linksPad;
    }
    if(isset($start)){
    //if($start > 1){
    if($this->currentPage > 1){
    if(!empty($this->pageJumpBack)){
    $pageNum = $start - $this->linksToDisplay + $linksPad;

    if($pageNum linksHref.$queryString.$pageNum.’”>’;
    $strLinks .= $this->pageJumpBack.'’.$this->pageSeparator;
    }
    if(($this->currentPage - $linksPad) > 1) {
    $strLinks .= ‘linksHref.$queryString.’1″>1…‘.$this->pageSeparator;
    }
    }
    if($start + $this->linksToDisplay > $pageCount){
    $end = $pageCount;
    }
    else {
    $end = $start + $this->linksToDisplay - 1;
    }
    for($i = $start; $i currentPage){
    $strLinks .= ‘linksHref.$queryString.($i).’”>’;
    $strLinks .= ($i).’
    ‘.$this->pageSeparator;
    }
    else {
    $strLinks .= $i.$this->pageSeparator;
    }
    }
    $strLinks = substr($strLinks, 0, -strlen($this->pageSeparator));
    if($start + $this->linksToDisplay - 1 pageSeparator.’linksHref.$queryString.$pageCount.’”>’;
    //$strLinks .= ‘…’.$pageCount.’
    ‘.$this->pageSeparator;
    $strLinks .= ‘…’.$pageCount.'’;
    }
    if(!empty($this->pageJumpNext) && $this->currentPage linksToDisplay + $linksPad;
    if($pageNum > $pageCount){
    $pageNum = $pageCount;
    }*/
    $pageNum = $this->currentPage + 1;
    $strLinks .= $this->pageSeparator . ‘ linksHref.$queryString.$pageNum.’”>’;
    $strLinks .= $this->pageJumpNext.’
    ‘;
    }
    }
    return $strLinks;
    }

  94. Nick said,

    on April 22nd, 2007 at 12:43 pm

    Update: Back button still was not going back only one page. Fixed in this code:

    function GetPageLinks(){
    $strLinks = ‘’;
    $pageCount = $this->GetPageCount();
    $queryString = $this->GetQueryString();
    $linksPad = floor($this->linksToDisplay/2);

    if($this->linksToDisplay == -1){
    $this->linksToDisplay = $pageCount;
    }
    if($pageCount == 0){
    $strLinks = ‘1′;
    }
    elseif($this->currentPage - 1 linksToDisplay + 1 == 0) || $this->linksToDisplay > $pageCount){
    $start = 1;
    }
    elseif($pageCount - $this->currentPage linksToDisplay + 1;
    }
    else {
    $start = $this->currentPage - $linksPad;
    }
    if(isset($start)){
    //if($start > 1){
    if($this->currentPage > 1){
    if(!empty($this->pageJumpBack)){
    /* $pageNum = $start - $this->linksToDisplay + $linksPad;

    if($pageNum currentPage - 1;
    $strLinks .= ‘linksHref.$queryString.$pageNum.’”>’;
    $strLinks .= $this->pageJumpBack.’
    ‘.$this->pageSeparator;
    }
    if(($this->currentPage - $linksPad) > 1) {
    $strLinks .= ‘linksHref.$queryString.’1″>1…‘.$this->pageSeparator;
    }
    }
    if($start + $this->linksToDisplay > $pageCount){
    $end = $pageCount;
    }
    else {
    $end = $start + $this->linksToDisplay - 1;
    }
    for($i = $start; $i currentPage){
    $strLinks .= ‘linksHref.$queryString.($i).’”>’;
    $strLinks .= ($i).’
    ‘.$this->pageSeparator;
    }
    else {
    $strLinks .= $i.$this->pageSeparator;
    }
    }
    $strLinks = substr($strLinks, 0, -strlen($this->pageSeparator));
    if($start + $this->linksToDisplay - 1 pageSeparator.’linksHref.$queryString.$pageCount.’”>’;
    //$strLinks .= ‘…’.$pageCount.’
    ‘.$this->pageSeparator;
    $strLinks .= ‘…’.$pageCount.'’;
    }
    if(!empty($this->pageJumpNext) && $this->currentPage linksToDisplay + $linksPad;
    if($pageNum > $pageCount){
    $pageNum = $pageCount;
    }*/
    $pageNum = $this->currentPage + 1;
    $strLinks .= $this->pageSeparator . ‘ linksHref.$queryString.$pageNum.’”>’;
    $strLinks .= $this->pageJumpNext.’
    ‘;
    }
    }
    return $strLinks;
    }

  95. Brady said,

    on April 22nd, 2007 at 2:01 pm

    Thanks, Nick. Was there anything that needs fixing in the original script, or are these just changes to suit personal preferences? I realize that the functionality is kinda weird, so I was working on a second release to this that offered different methods of pagination, but I never got around to releasing it. I believe everything works perfectly in the new version, but there are things I’d like to change. Let me know if you’d like a copy of it and I’ll send it your way.


  96. on July 4th, 2007 at 10:50 am

    […] Paginate database results
    Pagination: Easy as PREV 1 2 3 NEXT
    PHP Pagination with MySQL
    PaginateIt - A PHP Pagination Class
    […]

  97. Paul said,

    on August 2nd, 2007 at 11:39 am

    I just recently found your paginate class. It works great, but I have one question. I set it up with 10 links per page, 10 items per page, and there are 390