dongyo1818 2018-08-01 06:20
浏览 33

PHP分页集成脚本在输出中不显示页面

Greetings Stackoverflow,

I'm a complete newbie when it comes to executing a working pagination script.

Here I've got a php script that takes out data from a mysql table and displays it right on a webpage, which has been working pretty nicely, until I decided to add some pagination to it.

No other errors except undefined 's' and 'page', but the bigger problem that I think is with $limit as a larger number larger than 71 gets the undefined errors to disappear (because the sqltable contains 70 entries). So basically, I'd love to get some help from you pros out there to figure out what in my script is wrong enough that it is just not displaying 'pages' in the output.

Here's possibly everything you'd need :

    $sql_conn = mysqli_connect( $sql_host, $sql_user, $sql_pass,$sql_db);
$zone="-14400"; //USA Time Zone
$targetpage = "advanced_bans.php";
$limit = 40;  // Entries Showed per page

// Start Pagination
$sql_query = "SELECT COUNT(*) as num FROM $stable";
$sql_res=mysqli_query($sql_conn,$sql_query);
$total_pages = mysqli_fetch_array($sql_res,MYSQLI_NUM);
#the number of pages
foreach ($sql_res as $res) {
    $num=$res['num'];
}
$total_pages=$num;

$stages = 3;
$start = 0;
$page = mysqli_real_escape_string($sql_conn , $_GET['page']);
if($page){
    $start = ($page - 1) * $limit;
}else{
    $start = 0;
}  
// Get page data

// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;                        
$lastpage = ceil($total_pages/$limit);    
$LastPagem1 = $lastpage - 1;                  


$paginate = '';
if($lastpage > 1)
{  



    $paginate .= "<div class='paginate'>";
    if ($page > 1){
        $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$prev'>previous</a>";
    }else{
        $paginate.= "<span class='disabled'>previous</span>";   }


    if ($lastpage < 7 + ($stages * 2))  // Not enough pages to breaking it up
    {  
        for ($counter = 1; $counter <= $lastpage; $counter++)
        {
            if ($counter == $page){
                $paginate.= "<span class='current'>$counter</span>";
            }else{
                $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$counter'>$counter</a>";}                  
        }
    }
    elseif($lastpage > 5 + ($stages * 2))   // Enough pages to hide a few?
    {
        if($page < 1 + ($stages * 2))      
        {
            for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
            {
                if ($counter == $page){
                    $paginate.= "<span class='current'>$counter</span>";
                }else{
                    $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$counter'>$counter</a>";}                  
            }
            $paginate.= "...";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$LastPagem1'>$LastPagem1</a>";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$lastpage'>$lastpage</a>";    
        }
        elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
        {
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=1'>1</a>";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=2'>2</a>";
            $paginate.= "...";
            for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
            {
                if ($counter == $page){
                    $paginate.= "<span class='current'>$counter</span>";
                }else{
                    $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$counter'>$counter</a>";}                  
            }
            $paginate.= "...";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$LastPagem1'>$LastPagem1</a>";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$lastpage'>$lastpage</a>";    
        }
        else
        {
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=1'>1</a>";
            $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=2'>2</a>";
            $paginate.= "...";
            for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
            {
                if ($counter == $page){
                    $paginate.= "<span class='current'>$counter</span>";
                }else{
                    $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$counter'>$counter</a>";}                  
            }
        }
    }

    // Next
    if ($page < $counter - 1){
        $paginate.= "<a href='$targetpage?s=".$_GET['s']."&page=$next'>next</a>";
    }else{
        $paginate.= "<span class='disabled'>next</span>";
    }

    $paginate.= "</div>";   } 

Hope I'll learn something to keep in mind from this, Thanks and Regards, ZEDD

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值