0

我已经在我的 pg_management.php 文件中完成了分页,该文件显示了存储在数据库中的所有记录。问题是当我移到下一页时,没有显示下一页。当我将指针移到链接上时,链接没有悬停。

下面是我的分页代码

<?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";       
    }
    ?>

下面是打印分页的语法

<?php echo $pagination; ?> 

这是我的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;
    }
4

1 回答 1

0

这是准备使用用户定义的函数来呈现分页链接。

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;               

}
于 2012-12-25T16:28:24.250 回答