+ Post New Thread
Results 1 to 10 of 10
Web Development Thread, PHP Paginating in Coding and Web Development; Can anybody point me in the direction of a VERY easy to implement PHP Paginating script? Many thanks...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    239

    PHP Paginating

    Can anybody point me in the direction of a VERY easy to implement PHP Paginating script?

    Many thanks

  2. IDG Tech News
  3. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,856
    Thank Post
    412
    Thanked 776 Times in 649 Posts
    Rep Power
    170
    #define('paginating'=?)

  4. #3

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,330
    Blog Entries
    2
    Thank Post
    604
    Thanked 900 Times in 630 Posts
    Rep Power
    296

  5. #4

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    15,270
    Blog Entries
    24
    Thank Post
    489
    Thanked 1,940 Times in 1,520 Posts
    Rep Power
    659
    What are you paginating? MySQL? LDAP? MSSQL? etc...

  6. #5

    Join Date
    Oct 2008
    Location
    Gosport
    Posts
    64
    Thank Post
    1
    Thanked 18 Times in 13 Posts
    Rep Power
    13
    If it's MySQL you're taking your data from, the LIMIT clause may be very useful to you.

    PHP Code:
    <?php
    $perPage 
    20;
    $pageNum = (int)$_GET['pagenum'];

    if( 
    $pagenum ) { $pageNum 0; }

    $from $pageNum $perPage;

    $query 'SELECT * FROM my_table LIMIT '.$from.', '.$perPage;
    // mysql connection stuffs...
    $data mysql_query($query);

    echo 
    '<table>';
    while( 
    $row mysql_fetch_assoc($data) ) {
      echo 
    '<tr><td>';
      
    var_dump($row);
      echo 
    '</td></tr>';
    }
    echo 
    '</table>';
    ?>
    The while loop is pretty generic and won't make things nice, but you (hopefully) get the idea.

    Hello
    :-Dave

    As always, code is untested and has no guarantees of any kind.

  7. #6

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    239
    Quote Originally Posted by webman View Post
    Now now webman, no need to be sarcy. Yes, I did try Google but was posting here to get recommendations

  8. #7
    tsky's Avatar
    Join Date
    Jan 2009
    Location
    Billingham
    Posts
    200
    Thank Post
    10
    Thanked 26 Times in 16 Posts
    Rep Power
    16
    If you're grabbing from MySQL or suchlike, use the limit function of SQL... easiest and simplest way!

  9. #8

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    239
    Quote Originally Posted by tsky View Post
    If you're grabbing from MySQL or suchlike, use the limit function of SQL... easiest and simplest way!
    I am using MySQL - do you have this in an example.

  10. #9

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,856
    Thank Post
    412
    Thanked 776 Times in 649 Posts
    Rep Power
    170
    SELECT * FROM table WHERE thing=true LIMIT 10;

    gets the first ten records returned only

    SELECT * FROM table WHERE thing=true LIMIT 10, 10;

    gets ten records from row eleven onwards (note: add an ORDER BY if you want to be able to predict what you'll be getting).

  11. #10
    tsky's Avatar
    Join Date
    Jan 2009
    Location
    Billingham
    Posts
    200
    Thank Post
    10
    Thanked 26 Times in 16 Posts
    Rep Power
    16
    Quote Originally Posted by Hightower View Post
    I am using MySQL - do you have this in an example.
    you can always create a chunk of php code around your main loop to return pages of information - e.g. off the top of my head (from things I've done in the past):
    ----------------------------------
    $sql = "SELECT * FROM mytable ";

    if(($pageStart == "")||($pageStart < 0)){
    $pageStart = 0;
    }


    $sql .= "LIMIT $pageStart,50";

    $result = @mysql_query($sql);

    while($resultArray = @mysql_fetch_array($result)){
    // Grab a new row of data
    // Do your grab / display routine here
    $pageStart++;
    }

    // To create a google-esque page list
    $sql = "SELECT * FROM tablename";
    $PageNum = 0; // Set First Page
    $numPages = 0; // Set zero number of pages to display
    $result = @mysql_query($sql);
    $numresults = @mysql_num_rows($result);

    while($numPages <= $numresults){
    print "<a href=\"thisscriptpage.pgp&pageStart=$numPages\"> $PageNum </a>";
    $PageNum++;
    $numPages = $numPages + 50;
    }

    ------------------------------

    This will create a page with fifty entries per page, if you enter the page with no starting point it will display from the beginning...

    hope that helps a bit - PM me if you need a bit more info.

SHARE:
+ Post New Thread

Similar Threads

  1. PHP
    By faza in forum How do you do....it?
    Replies: 4
    Last Post: 3rd December 2008, 01:56 PM
  2. PHP ID
    By Jackd in forum Coding
    Replies: 4
    Last Post: 30th November 2008, 01:08 PM
  3. PHP Help!
    By Cravon in forum Coding
    Replies: 2
    Last Post: 20th November 2007, 05:05 PM
  4. Help with PHP
    By Gatt in forum Web Development
    Replies: 1
    Last Post: 14th November 2006, 09:01 PM
  5. php help
    By beeswax in forum Windows
    Replies: 33
    Last Post: 14th October 2005, 04:51 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •