Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts

    pagination question

    Hi,

    I am trying out a simple test pagination script on records in my database (i have good few stored) I have managed to write a script that displays the page numbers and previous and next links (displaying 10 records per page), but I would like the numbers to cut off, as they go right across the page (nearly:eek: ) say for example, like this:

    < Previous 1,2...10,11,12...39,40 Next >

    how is this done :confused:

    here is the code:

    PHP Code:
    <?php
    mysql_connect
    ("localhost""root""") or die("ERROR - CANNOT CONNECT TO SERVER");
    mysql_select_db("new_test") or die("ERROR - CANNOT OPEN DATABASE");

    if (!isset(
    $_GET['page'])) {
    $page 1;
    } else {
    $page $_GET['page'];
    }

    $max_results 10;

    $from = (($page $max_results) - $max_results);

    $sql mysql_query("SELECT * from mix_send order by mix_send_id desc LIMIT $from, $max_results");
    while (
    $row mysql_fetch_array($sql)) {
    ?>

    <?php echo $row['mix_send_djname']; ?><br />

    <?php
    }

    $total_results mysql_result(mysql_query("SELECT COUNT(*) as Num from mix_send"),0);

    $total_pages ceil($total_results $max_results);

    if (
    $page 1) {
    $prev = ($page 1);
    echo 
    "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">&lt;&lt;Previous</a> ";
    }

    for(
    $i 1$i <= $total_pages$i++) {
    if ((
    $page) == $i) {
    echo 
    "$i ";
    } else {
    echo 
    "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
    }

    if (
    $page $total_pages) {
    $next = ($page 1);
    echo 
    "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">&gt;&gt;Next Page</a> ";
    }
    ?>

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    There is a pagination class in the Post a PHP Snippet forum which should do this for you.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Thanks


  •  

    Posting Permissions

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