如何在php中使用分页

如何在php中使用分页,php,mysql,pagination,Php,Mysql,Pagination,您好,我正在使用分页从数据库检索数据,我可以检索到,但我面临的问题是,在我的分页下一个和最后一个按钮不工作 这是我的密码 **index.php** <script type="text/javascript"> function searchboxfun(numRecords, pageNum ) { $.ajax({ type: "GET", url: "usersearchboxresult.php?search=" +

您好,我正在使用分页从数据库检索数据,我可以检索到,但我面临的问题是,在我的分页下一个和最后一个按钮不工作

这是我的密码 **index.php**

<script type="text/javascript">
        function searchboxfun(numRecords, pageNum ) {
    $.ajax({
        type: "GET",
        url: "usersearchboxresult.php?search=" + document.getElementById("UserSearchBox").value,
        data: "show="+numRecords+"&pagenum="+pageNum,
        cache: false,
        beforeSend: function () { 
            $('#content').html('<img src="loader.gif" alt="" width="24" height="24" style=" padding-left:469px;">');
        },
        success: function(html) {    
            $("#RightPaneContainerDiv").html( html );
        }
    });
    return false;
}

function changeDisplayRowCount(numRecords)  {
    searchboxfun(numRecords, 1);
}

$( document ).ready(function() {
  searchboxfun(10, 1);
});  
</script>
 <form name="myForm" id="Myform" action="#" onsubmit="return  searchboxfun(); ">
<input type="text" id="UserSearchBox" name="UserSearchBox" style="width: 95%; margin-top: 15px; margin-left: 2%;" placeholder="Search Box"/>
 <div style="float: right; margin-right: 2%; margin-top: 0px;">
 <input type="submit" name="Search" value="Search" id="search" onclick='searchboxfun();'>
 </div>
</form>

函数searchboxfun(numRecords,pageNum){
$.ajax({
键入:“获取”,
url:“usersearchboxresult.php?search=“+document.getElementById(“UserSearchBox”).value,
数据:“show=“+numRecords+”&pagenum=“+pagenum,
cache:false,
beforeSend:函数(){
$('#content').html('');
},
成功:函数(html){
$(“#RightPaneContainerDiv”).html(html);
}
});
返回false;
}
函数changeDisplayRowCount(numRecords){
searchboxfun(numRecords,1);
}
$(文档).ready(函数(){
searchboxfun(10,1);
});  
usersearchboxresult.php

<?php
session_start();
?>
<head>
<style>
.hidden { display: none; }
</style>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script language="javascript" src="users.js" type="text/javascript"></script>
<script src="jquery.js"></script>
</head>
<?php

require_once("configure.php");

// Very important to set the page number first.
if (!(isset($_GET['pagenum']))) { 
     $pagenum = 1; 
} else {
    $pagenum = $_GET['pagenum'];        
}

//Number of results displayed per page  by default its 10.
$page_limit =  ($_GET["show"] <> "" && is_numeric($_GET["show"]) ) ? $_GET["show"] : 10;

// Get the total number of rows in the table
//$sql = "SELECT * FROM tbl_pagination  WHERE 1" ;

$search=$_GET['search'];
$eid=$_SESSION['eid'];

$sql="select * from clientreg where eid=$eid and (mobile like '%$search%' or fname like '%$search%' or service like '%$search%')";
//$select_table = "";
$cnt = mysql_num_rows( mysql_query($sql))or die("There is no record in Database!");

//Calculate the last page based on total number of rows and rows per page. 
$last = ceil($cnt/$page_limit); 

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) { 
    $pagenum = 1; 
} elseif ($pagenum > $last)  { 
    $pagenum = $last; 
}

$lower_limit = ($pagenum - 1) * $page_limit;


$sql2 = $sql . " limit ". ($lower_limit)." ,  ". ($page_limit). " ";
$rs = mysql_query($sql2);   
?>
<form name="frmUser" method="post" action="">
<div style="width:98%; margin-left:20px;">
<table border="0" cellpadding="10" cellspacing="1" width="100%" class="tblListForm">

        <?php
            $j=0;
            $countleadmodified=array();
    $countResult = 0;   
    while ( $row = mysql_fetch_array($rs) ) {
<tr>
<td><input type="checkbox" name="users[]" class="users" value="<?php echo $row["id"]; ?>" ></td>
<td>&#10032;</td>
<td><?php echo $_SESSION['user'];?></td>
<td><?php echo $row["fname"];?></td>
<td><?php echo $row["lname"];?></td>
<td><?php echo $row["mobile"];?></td>

</tr>
        <?php
    $j++;

    }
    ?>


      </table>

</div>
</form>
<div id="paging">
<div class="height30"></div>
<table width="50%" border="0" cellspacing="0" cellpadding="2"  align="center">
<tr>
  <td valign="top" align="left">

<label> Rows Limit: 
<select name="show" onChange="changeDisplayRowCount(this.value);">
  <option value="10" <?php if ($_GET["show"] == 10 || $_GET["show"] == "" ) { echo ' selected="selected"'; }  ?> >10</option>
  <option value="20" <?php if ($_GET["show"] == 20) { echo ' selected="selected"'; }  ?> >20</option>
  <option value="30" <?php if ($_GET["show"] == 30) { echo ' selected="selected"'; }  ?> >30</option>
</select>
</label>

    </td>
  <td valign="top" align="center" >

    <?php
    if ( ($pagenum-1) > 0) {
    ?>  
     <a href="javascript:void(0);" class="links" onclick="displayRecords('<?php echo $page_limit;  ?>', '<?php echo 1; ?>');">First</a>
    <a href="javascript:void(0);" class="links"  onclick="displayRecords('<?php echo $page_limit;  ?>', '<?php echo $pagenum-1; ?>');">Previous</a>
    <?php
    }


    //Show page links
    for($i=1; $i<=$last; $i++) {
    $j=1;
        if ($i == $j) {
?>
        <!--<a href="javascript:void(0);" class="selected" ><?php echo $i ?></a>-->
<?php
    } else {  
?>
    <a href="javascript:void(0);" class="hidden"  onclick="displayRecords('<?php echo $page_limit;  ?>', '<?php echo $i; ?>');" ><?php echo $i ?></a>
<?php 
    }
$j++;}



if ( ($pagenum+1) <= $last) {
?>
    <a href="javascript:void(0);" onclick="displayRecords('<?php echo $page_limit;  ?>', '<?php echo $pagenum+1; ?>');" class="links">Next</a>
<?php } if ( ($pagenum) != $last) { ?>  
    <a href="javascript:void(0);" onclick="displayRecords('<?php echo $page_limit;  ?>', '<?php echo $last; ?>');" class="links" >Last</a> 
<?php
    } 
?>
</td>
    <td align="right" valign="top">
    Page <?php echo $pagenum; ?> of <?php echo $last; ?>
    </td>
</tr>
</table>
 </div>

.hidden{显示:无;}

您的代码有dreamweaver自动生成代码的味道。
$page\u limit=($\u GET[“show”]”和&is\u numeric($\u GET[“show”])$_获取[“显示”]:10-->帕斯卡多少?您没有使用
$\u GET[“show”]“”
。我认为
不应该起作用!你应该使用
=或根本不进行比较(只要
$page\u limit=($\u GET[“show”]/1)?$\u GET[“show”]:10;
就足够了)。