dropdownlist中的Php分页

dropdownlist中的Php分页,php,jquery,Php,Jquery,我有动态Dropdownlist和php分页。我想为页码创建一个下拉列表。我不希望有正常的分页(下一个是prev1-2-3),而是希望这些分页在下拉列表中。 类似于在管理页面中,下拉菜单可以帮助您快速移动到所需页面 就像在Phpmyadmin这样 这是我右边的代码行 首页 <script> function showUser(str,ids) { var $txtHint = $('#txtHint'); if (str=="" || ids=="") {

我有动态Dropdownlist和php分页。我想为页码创建一个下拉列表。我不希望有正常的分页(下一个是prev1-2-3),而是希望这些分页在下拉列表中。 类似于在管理页面中,下拉菜单可以帮助您快速移动到所需页面

就像在Phpmyadmin这样

这是我右边的代码行

首页

<script>
function showUser(str,ids) {
    var $txtHint = $('#txtHint');
    if (str=="" || ids=="") {
        $txtHint.html('');
        return;
    }
    $txtHint.load('app_list.php?q='+str+'&id='+ids) 
}

</script>

函数showUser(str,ids){
var$txtHint=$(“#txtHint”);
如果(str==“”| | ids==“”){
$txtHint.html(“”);
返回;
}
$txtHint.load('app_list.php?q='+str+'&id='+ids)
}
第二页

$id = $mysqli->real_escape_string($_GET["q"]);
$id2 = $mysqli->real_escape_string($_GET["id"]);
if (isset($_GET['id'])) { 
    $id2 = preg_replace('#[^0-9]#i', '', $_GET['id']); 
} else { 
    $id2 = 1;
} 
$itemsPerPage = 100; 
$lastPage = ceil($nr / $itemsPerPage);
if ($id2 < 1) { 
    $id2 = 1; 
} else if ($id2 > $lastPage) { 
    $id2 = $lastPage; 
} 

$centerPages = "";
$sub1 = $id2 - 1;
$sub2 = $id2 - 2;
$add1 = $id2 + 1;
$add2 = $id2 + 2;
if ($id2 == 1) {

    $centerPages .= '&nbsp; <span class="pagNumActive">' . $id2 . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $add1 .'")>' . $add1 . '</a> &nbsp;';
} else if ($id2 == $lastPage) {
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $sub1 .'")>' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $id2 . '</span> &nbsp;';
} else if ($id2 > 2 && $id2 < ($lastPage - 1)) {
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $sub2 .'")>' . $sub2 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $sub1 .'")>' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $id2 . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $add1 .'")>' . $add1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $add2 .'")>' . $add2 . '</a> &nbsp;';
} else if ($id2 > 1 && $id2 < $lastPage) {
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $sub1 .'")>' . $sub1 . '</a> &nbsp;';
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $id2 . '</span> &nbsp;';
    $centerPages .= '&nbsp; <a href="#" onclick=showUser(str="'. $id .'",ids="'. $add1 .'")>' . $add1 . '</a> &nbsp;';
}

$limit = 'LIMIT ' .($id2 - 1) * $itemsPerPage .',' .$itemsPerPage; 

//query

$paginationDisplay = "";
if ($lastPage != "1"){
    $paginationDisplay .= 'Page <strong>' . $id2 . '</strong> of ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
    if ($id2 != 1) {
        $previous = $id2 - 1;
        //$paginationDisplay .=  '&nbsp;  <a href="next?id=' . $previous . '"> Back</a> ';
        $paginationDisplay .=  '&nbsp;  <a href="#" onclick=showUser(str="'. $id .'",ids="'. $previous .'")> Back</a> ';
    }                                               
    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
    if ($id2 != $lastPage) {
        $nextPage = $id2 + 1;
        $paginationDisplay .=  '&nbsp;  <a href="#" onclick=showUser(str="'. $id .'",ids="'. $nextPage .'")> Next</a> ';
        //$paginationDisplay .=  '&nbsp;  <a href="next.php?id=' . $nextPage . '"> Next</a> ';
    } 
}
$id=$mysqli->real\u escape\u字符串($\u GET[“q”]);
$id2=$mysqli->real\u escape\u字符串($\u GET[“id]”);
如果(isset($_GET['id']){
$id2=preg#u replace('#[^0-9]#i','''.$#u GET['id']);
}否则{
$id2=1;
} 
$itemsPerPage=100;
$lastPage=ceil($nr/$itemsPerPage);
如果($id2<1){
$id2=1;
}如果($id2>$lastPage){
$id2=$lastPage;
} 
$centerPages=“”;
$sub1=$id2-1;
$sub2=$id2-2;
$add1=$id2+1;
$add2=$id2+2;
如果($id2==1){
$centerPages.=''.$id2';
$centerPages.='';
}else if($id2==$lastPage){
$centerPages.='';
$centerPages.=''.$id2';
}如果($id2>2&&$id2<($lastPage-1)){
$centerPages.='';
$centerPages.='';
$centerPages.=''.$id2';
$centerPages.='';
$centerPages.='';
}否则如果($id2>1&&$id2<$lastPage){
$centerPages.='';
$centerPages.=''.$id2';
$centerPages.='';
}
$limit='limit'($id2-1)*$itemsPerPage','.$itemsPerPage;
//质疑
$paginationDisplay=“”;
如果($lastPage!=“1”){
$paginationDisplay.='Page。$id2.共'$lastPage';
如果($id2!=1){
$previous=$id2-1;
//$paginationDisplay.='';
$paginationDisplay.='';
}                                               
$paginationDisplay.=''.$centerPages';
如果($id2!=$lastPage){
$nextPage=$id2+1;
$paginationDisplay.='';
//$paginationDisplay.='';
} 
}

我怎么能做到?一些帮助。。。感谢advance

要显示页码,您必须首先根据结果和页数限制计算页数

在获取结果计数的SQL查询中使用“SQL\u CALC\u FOUND\u ROWS as COUNT”列。并将其存储在变量中,比如$total_results

使用公式计算页数

$page_count = ($total_results / $page_limit) + 1
在哪里,

$page_count => The number of pages available \n
$total_results => The number of result rows (from sql query COUNT)
$page_limit => Number of results shown in each page
在PHP页面中,按如下方式打印HTML以供下拉

<select id='pageNo'>
    <?php
        for($i=1; $i < $page_count; $i++) {
            echo "<option value='".$i."'>".$i."</option>";
        }
    ?>
</section>

我希望这对你有帮助。请根据您的需要对此进行修改。

我在jquery中遇到了困难。如何在jquery中混合使用它?这是一个独立的剧本。您可以将其放置在页面javascript文件中的任何位置。下拉列表是正确的。但当我尝试选择时,什么都没有发生。你能解释一下吗?我有两页。第1页,有一个jquery来修改动态下拉列表。第2页有SQL查询。您是否按照我的说明完成了SQL和php部分。那么,你有没有包含可用页数的下拉列表。我真的需要完成这个脚本
$('#pageNo').on('change', function(){
    var loadPage = $('#pageNo').val();
    // Do your page submit to load another page
});