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