Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2014
    Thanked 0 Times in 0 Posts

    Blog - Limit posts on page, next page

    Hi everyone. I'm a bit stuck on limiting posts on a page for a blog, and then have next page(page numbers). See the simple script below.

    PHP Code:
    echo "
    <div class='blog_post_container'>
        <div class='blog_post_title'>
        <div class='blog_post_date'>
            <div class='blog_post_content'>
    <hr class='blog_hr'>

    Contents of the database (my blog posts) are being pulled through to a single page.

    Not ideal if I have 20 posts as all on one page.

    Does anyone know how I can limit this to 10 on the page?, I would quite like to have some sort of next page links or page numbers after 10 posts?

    Even better if someone knows a youTube video or some other good resource to help?

    Don't knwo where to begin with this so any help most appriciated.

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    Paging if very very easy with MySQL!

    You just have to use the LIMIT keyword in you query.

    So something as simple as this:
    $pageSize = 10; // or any other size
    $pageNumber = $_REQUEST("pageNumber"); // get page number from GET or POST
    if ( ! isset($pageNumber) ) $pageNumber = 1;
    $startLimit = ( $pageNumber - 1 ) * $pageSize;
    $sql = "SELECT ... FROM ... ORDER BY ... LIMIT $startLimit, $pageSize";
    Be yourself. No one else is as qualified.


Posting Permissions

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