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
    New Coder
    Join Date
    Oct 2009
    Location
    Dallas,Tx USA
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    pagination in php

    Hey ,

    I am trying to do pagination using this code. It adds the first previous, next and last links to the page but when i click on them they doesnt take me to next pages..am i missing some thing...plz help.....

    PHP Code:
    function addNavigation($currentPage) {
        $params = "";

        foreach($_GET as $key => $value) {
            if($key != 'pageNum') {
                $params .= "&$key=$value";
            }
        }
        $_SESSION['totalPages'] = ceil($_SESSION['totalRows']/$_SESSION['maxRows']);
    ?>

    <p />
    <table width="382px" height="34px" border="0" align="center" background="../ts_images/bg_navagation.gif">
      <tr valign="middle">
          <td width="25%" align="center" valign="middle"><img <?php
                
    if($_SESSION['pageNum'] > 1) {
                    echo 
    ' src="../ts_images/btn_first.gif" ';
                
    ?>
                    onClick="MM_goToURL('parent','<?php $args sprintf("%s?pageNum=1"$currentPage); if(strlen($params) > 0$args .= "&$params"; echo $args?>');return document.MM_returnValue"
                <?php } else {
                    echo 
    ' src="../ts_images/btn_first_off.gif" ';
                } 
    ?>
            />
        </td>
        <td width="25%" align="center" valign="middle"><img  <?php
                
    if($_SESSION['pageNum'] > 1) {
                    echo 
    ' src="../ts_images/btn_prev.gif" '?>
                    onClick="MM_goToURL('parent','<?php $args sprintf("%s?pageNum=%d"$currentPagemax(1$_SESSION['pageNum'] - 1)); if(strlen($params) > 0$args .= "&$params"; echo $args?>');return document.MM_returnValue"
                <?php } else {
                    echo 
    ' src="../ts_images/btn_prev_off.gif" ';
                } 
    ?>
                />
        </td>
        <td width="25%" align="center" valign="middle"><img <?php
                
    if ($_SESSION['pageNum'] < $_SESSION['totalPages']) {
                    echo 
    ' src="../ts_images/btn_next.gif" '?>
                    onClick="MM_goToURL('parent','<?php $args sprintf("%s?pageNum=%d"$currentPagemin($_SESSION['totalPages'], $_SESSION['pageNum'] + 1)); if(strlen($params) > 0$args .= "&$params"; echo $args?>');return document.MM_returnValue"
                <?php } else {
                    echo 
    ' src="../ts_images/btn_next_off.gif" ';
                } 
    ?>
                />
        </td>
        <td width="25%" align="center" valign="middle"><img <?php
                
    if ($_SESSION['pageNum'] < $_SESSION['totalPages']) {
                    echo 
    ' src="../ts_images/btn_last.gif" '?>
                    onClick="MM_goToURL('parent','<?php $args sprintf("%s?pageNum=%d"$currentPage$_SESSION['totalPages']); if(strlen($params) > 0$args .= "&$params"; echo $args?>');return document.MM_returnValue"
                <?php } else {
                    echo 
    ' src="../ts_images/btn_last_off.gif" ';
                } 
    ?>
                />
        </td>
      </tr>
    </table>
    <table border="0" width="50%" align="center">
      <tr>
        <td align="right" width="50%">Records</td>
        <td><div align="left">
            <?php if($_SESSION['totalRows'] > 0) {
                        echo 
    $_SESSION['startRow'].'&nbsp; to &nbsp;'.min($_SESSION['startRow'] + $_SESSION['maxRows'] - 1$_SESSION['totalRows']).' of &nbsp;'.$_SESSION['totalRows'].'';
                    }
                    else {
                        echo 
    '0 to 0 of &nbsp;0';
                    }
                
    ?>
          </div></td>
      </tr>
      <tr>
        <td align="right" width="50%">Page</td>
        <td><div align="left">
            <?php if($_SESSION['totalRows'] > 0) {
                        echo 
    $_SESSION['pageNum'].'&nbsp; of &nbsp;'.$_SESSION['totalPages'].'';
                    }
                    else {
                        echo 
    '0 to 0 of &nbsp;0';
                    }
                
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Is that your complete code? Show the rest of code that handles the value of variable pageNum
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You shouldn't be using javascript for these. It should be <a> tags around them. When you view the source what does the onClick for the pages have in them?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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