简体   繁体   English

分页中未显示下一页

[英]The next page is not shown in pagination

I have done pagination in my pg_management.php file that displays all records stored in database. 我已经在pg_management.php文件中完成了分页,该文件显示了存储在数据库中的所有记录。 The problem is When I move to next page , the next page is not shown. 问题是当我移至下一页时,不显示下一页。 When i move my pointer over the link, the link is not hovered. 当我将指针移到链接上时,链接不会悬停。

Below is my code for pagination 以下是我的分页代码

<?php 

    <?php   $tbl_name=$db_prefix."pages";
        $adjacents = 3;
        $query = "SELECT COUNT(*) as num FROM $tbl_name";
        $total_pages = mysql_fetch_array(mysql_query($query));
        $total_pages = $total_pages['nu

    m'];
        $targetpage = "pg_management.php"; 
        $limit = 2; 
        $page = 15;
        if($page) 
            $start = ($page - 1) * $limit;  
            else
            $start = 0;



    $sql = "SELECT page_name, status FROM $tbl_name LIMIT $start, $limit";
            $result = mysql_query($sql);
            if ($page == 0) $page = 1;
            $prev = $page - 1;
            $next = $page + 1;
            $lastpage = ceil($total_pages/$limit);
            $lpm1 = $lastpage - 1;
            $pagination = "";
    if($lastpage > 1)


    {   
            $pagination .= "<div class='pagination'>";

             if ($page > 1) 
                $pagination.= "<a href='$targetpage?page=$prev'>previous</a>";
            else
                $pagination.= "<span class='disabled'>previous</span>"; 

                if ($lastpage < 7 + ($adjacents * 2))

                {   
                for ($counter = 1; $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
                }


                }
            elseif($lastpage > 5 + ($adjacents * 2))

            {
                if($page < 1 + ($adjacents * 2))        
                {
                    for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)



{
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
                }
                $pagination.= "...";
                $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";


    $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";       
                    }

                    elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
                    {
                        $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                        $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
                        $pagination.= "...";
                        for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                        {
                            if ($counter == $page)
                                $pagination.= "<span class=\"current\">$counter</span>";

                                else


$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
                    }
                    $pagination.= "...";
                    $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";

                    $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";       
                }

            else
            {
                $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
                $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)

                {
                    if ($counter == $page)
                        $pagination.= "<span class=\"current\">$counter</span>";
                    else
                        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";                 
                }
            }
        }

        if ($page < $counter - 1) 
            $pagination.= "<a href=\"$targetpage?page=$next\">next </a>";
        else
            $pagination.= "<span class=\"disabled\">next </span>";
        $pagination.= "</div>\n";       
    }
    ?>

Below is syntax to print pagination 以下是打印分页的语法

<?php echo $pagination; ?> 

This is my css file 这是我的css文件

div.pagination
 {
font-family:Tahoma, Geneva, sans-serif;
    padding: 3px;
    margin: 3px;
}

div.pagination a 
{
    padding:2px 5px 2px 5px;
    margin:2px;
    border:1px solid #999;
    text-decoration:none;
    color: #666;
}

div.pagination a:hover, .pagination a:active 
{
    border: 1px solid #999;
    color: #000;
}

div.pagination span.current
 {
    margin: 2px;
    padding: 2px 5px 2px 5px;
    border: 1px solid #999;

        font-weight: bold;
        background-color: #999;
        color: #FFF;
    }

 div.pagination span.disabled {
        padding:2px 5px 2px 5px;
        margin:2px;
        border:1px solid #eee;
        color:#DDD;
    }

This is ready to use user defined function to render the pagination links. 准备使用用户定义的功能来呈现分页链接。

function do_pagination($mainsql,$targeturl)

{ {

$result = mysql_query($mainsql);
$count = mysql_num_rows($result);
$targetpage = $targeturl;   
$pagecount = $count / 10;
$pagecount = ceil($pagecount);
$end = $pagecount;
$links = "";
$curpage = $_GET['page'];
$start = 1;
$end = $pagecount;

$adjacents = 3;
$total_pages = $pagecount;  

if($curpage) 
    $start = ($page - 1) * $limit;          //first item to display on this page
else
    $start = 0; 

/* Setup page vars for display. */

if ($curpage == 0) $curpage = 1;                    //if no page var is given, default to 1.
$prev = $curpage - 1;                           //previous page is page - 1
$next = $curpage + 1;                           //next page is page + 1
$lastpage = $pagecount;             //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;      
$page = $curpage;

if($lastpage > 1)

{
    //previous button

    if ($page > 1) 

        $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$prev\">« previous</a>";

    else

        $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">« previous</span>";   



    //pages 

    if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up

    {   

        for ($counter = 1; $counter <= $lastpage; $counter++)

        {

            if ($counter == $page)

                $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">$counter</span>";

            else

                $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$counter\">$counter</a>";                    

        }

    }

    elseif($lastpage > 5 + ($adjacents * 2))    //enough pages to hide some

    {

        //close to beginning; only hide later pages

        if($page < 1 + ($adjacents * 2))        

        {

            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)

            {

                if ($counter == $page)

                    $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">$counter</span>";

                else

                    $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$counter\">$counter</a>";                    

            }

            $pagination.= "...";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$lpm1\">$lpm1</a>";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$lastpage\">$lastpage</a>";      

        }

        //in middle; hide some front and some back

        elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))

        {

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=1\">1</a>";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=2\">2</a>";

            $pagination.= "...";

            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)

            {

                if ($counter == $page)

                    $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">$counter</span>";

                else

                    $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$counter\">$counter</a>";                    

            }

            $pagination.= "...";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$lpm1\">$lpm1</a>";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$lastpage\">$lastpage</a>";      

        }

        //close to end; only hide early pages

        else

        {

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=1\">1</a>";

            $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=2\">2</a>";

            $pagination.= "...";

            for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)

            {

                if ($counter == $page)

                    $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">$counter</span>";

                else

                    $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$counter\">$counter</a>";                    

            }

        }

    }



    //next button

    if ($page < $counter - 1) 

        $pagination.= "<a style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\" href=\"$targetpage&page=$next\">next »</a>";

    else

        $pagination.= "<span style=\"margin-left:5px;margin-right:5px; background-color:#f8f8f8;border: 1px solid #cbcbcb; padding:5px;-moz-border-radius: 5px; -webkit-border-radius: 5px;\">next »</span>";



    echo $pagination;               

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM