SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php/ mysql - help with pagination

    I have created a simple cms and I need to have an archive page that shows ten articles per page, with a "< next | previous >" pagination system or similar.

    I have spent a long time away from php, and would dearly love it if somebody could show me how to do it, here is what I have now;

    PHP Code:
    <?php

    include "admin/dbconnect.php"
    include 
    "includes/format_date.php";

    $result mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 0,5");

    //echo's the articles, and even properly indents the code
    while($row mysql_fetch_array($result))
    {echo 
    "
    <p><em>"
    .$row['shortdescr']."</em></p>
    <p>"
    .$row['title']."</p>
    <p>"
    .$row['source']."</p>
    <p><strong>Posted on:</strong> "
    .$row['date']."</p>
    <hr />
    "
    ;
    }
    mysql_close($conn);
    ?>

  2. #2
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pull your page number into the script and use that to populate your pagination controls and to calculate your "LIMIT" in your SQL query.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The idea of pagination is that your code will calculate the maximum number of pages and then on each page will return the query with the LIMIT clause, that is set by the page number.

    I wrote a class, it is not OOP it is a beginner class, it is very simple.If you want i will post-it, a search will also help you with this issue.

  4. #4
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pistocel View Post
    The idea of pagination is that your code will calculate the maximum number of pages and then on each page will return the query with the LIMIT clause, that is set by the page number.

    I wrote a class, it is not OOP it is a beginner class, it is very simple.If you want i will post-it, a search will also help you with this issue.
    That would be a real help if you could post it for me, I will search anyway, but I'd already tried that so I'm not hopeful of finding something I can use!

    Thanks!

  5. #5
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is simple script u will find it helpful.

    http://www.codewalkers.com/c/a/Link-...de/Pagination/

  6. #6
    SitePoint Zealot Tjobbe's Avatar
    Join Date
    Sep 2004
    Location
    UK
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the link, I've just found this one too, which works for me: http://www.phpfreaks.com/tutorials/73/0.php


Bookmarks

Posting Permissions

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