CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP MySQL problem

    Pagination is a very simple task. The following should get you through it.

    PHP Code:
    <?php
    $show 
    10;
    $page = (isset($_GET['page'])) ? $_GET['page'] : 1;
    $page--; // because databases start at zero, humans start at one
    $start $page $show;

    $query "SELECT * FROM blog ORDER BY date DESC LIMIT $start$show";
    $sql mysql_query($query);
    $rows mysql_fetch_object(mysql_query("SELECT FOUND_ROWS() AS `rows`"))->rows;
    while (
    $row mysql_fetch_object($sql)) {
      
    // do your outputting from the database here
    }

    if (
    $page 0) {echo '<a href="?page=' $page '">&lt;&lt; Newer Posts</a>';}
    $total ceil(mysql_num_rows(mysql_query("SELECT id FROM blog")) / $show);
    if (
    $page $total 1) {echo '<a href="?page=' . ($page 2) . '">Older Posts &gt;&gt;</a>';}
    ?>
    Last edited by PeejAvery; March 28th, 2012 at 05:29 PM. Reason: Fixed the row count
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured