...

View Full Version : pagination in php



gadaschowdary
01-12-2010, 05:11 PM
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.....



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", $currentPage, max(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", $currentPage, min($_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';
}
?>

abduraooft
01-13-2010, 07:36 AM
Is that your complete code? Show the rest of code that handles the value of variable pageNum

JAY6390
01-13-2010, 01:23 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum