您的分页代码如下所示:
if($numrows!=0)
{
if($_REQUEST['rowsperpage'])
{
if(!isDigit($_REQUEST['rowsperpage']))
$rowsPerPage=10;
else
$rowsPerPage =$_REQUEST['rowsperpage'];
}
else
{
$rowsPerPage =10;
}
$pageNum = 1;
$mxpg=ceil($numrows/$rowsPerPage);
if($_REQUEST['pageNum']=='undefined' || $_REQUEST['pageNum']=='' || $_REQUEST['pageNum']==0 || ($_REQUEST['pageNum']>$mxpg) )
{
$pageNum=1;
}
else
{
if(isDigit($_REQUEST['pageNum']))
$pageNum=$_REQUEST['pageNum'];
else
$pageNum=1;
}
$offset = ($pageNum - 1) * $rowsPerPage;
$sqlal = $SQL_QUERY." limit $offset,$rowsPerPage;";
$resal=mysql_query($sqlal);
if(db_num_rows($resal)==0 && $pageNum > 1)
{
$pageNum = $pageNum - 1;
$offset = ($pageNum - 1) * $rowsPerPage;
$sqlal = $SQL_QUERY." limit $offset,$rowsPerPage;";
$resal=mysql_query($sqlal);
}
$maxpage=ceil($numrows/$rowsPerPage);
$othrparameter="rowsperpage=$rowsPerPage&frmdate=$frmdate&todate=$todate&srchcity=$srchcity"; //serch criteria if any
$tmpnavi=getnevigationhtml($pageNum,$maxpage,$file,$othrparameter);
$onlynum='"Numbers"';
$resultal = mysql_query($sqlal);
}
在 PHP 表单上显示如下:
<table width='100%'><tr>
<td align='left' >Rows : <input type='text' name='rowsperpage' id='rowsperpage' size='5' value='<?php echo $rowsPerPage;?>' onkeypress='return inputLimiter(event,<?php echo$onlynum;?>)' >
Go To Page: <input type='text' name='pageNum' id='pageNum' size='5' value='<?php echo $pageNum;?>' onkeypress='return inputLimiter(event,<?php echo$onlynum;?>)' >
<input type='submit' name='show' id='show' value='Show' >
</td>
<td align='left'><?php echo "Total :".$numrows;?></td>
<td align='right'><?php echo $tmpnavi; ?></td></tr></table>
您的记录获取将如下所示:
if($numrows>0){
while($res_image = mysql_fetch_array($resultal)){
//Your operations
}
}