2016-07-25 119 views
0

关于分页控件我如何让活动类工作。 a:active的CSS样式没有显示出来(控件上的其他所有内容都很好)。PHP分页控件风格

分页代码:

//start pagination 
//Get the total count of rows. 
$sql = "SELECT COUNT(id) FROM users"; 
$query = mysqli_query($dbc, $sql); 
$row = mysqli_fetch_row($query); 

//Here we have the total row count 
$rows = $row[0]; 

//Number of results to show per page 
$page_rows = 21; 

//This tells us the page number of our last page 
$last = ceil($rows/$page_rows); 

//This makes sure last cannot be less than 1 
if($last < 1){ 
    $last = 1; 
} 
//establish the $pagenum variable 
$pagenum = 1; 

//Get pagenum from URL vars if it is present, else it is = 1 
if(isset($_GET['pn'])){ 
    $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']); 
} 

//This makes sure the page number isn't below 1 or more than our $last page 
if($pagenum < 1){ 
    $pagenum = 1; 
} else if($pagenum > $last) { 
    $pagenum = $last; 
} 
//This sets the range of rows to query for the chosen $pagenum 
$limit = 'LIMIT ' . ($pagenum - 1) * $page_rows .',' .$page_rows; 

//This is your query again, it is for grabbing just one page worth of rows by applying the limit variable 
$sql = "SELECT id, image, fname, surname, address FROM users ORDER BY id DESC $limit"; 
$query = mysqli_query($dbc, $sql); 

//This shows the user what page they are on and the total number of pages 
$textline1 = "<b>$rows</b> Users"; 
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>"; 

//$paginationCrls variable 
$paginationCtrls = ' '; 

//if there is more than 1 page worth of results 
if($last != 1){ 
    /*First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page and to the previous page.*/ 

    if($pagenum > 1){ 
     $previous = $pagenum - 1; 
     $paginationCtrls .= '<a href="' . $_SERVER['PHP_SELF']. '?pn=' .$previous. '">&#171; Previous</a> &nbsp; &nbsp; '; 
     //Render clickable number links that should appear on the left of the target page number 
     for($i = $pagenum-4; $i < $pagenum; $i++){ 
      if($i > 0) {     
       $paginationCtrls .= '<a href="' .$_SERVER['PHP_SELF']. '?pn=' . $i .'">'.$i.'</a> &nbsp; &nbsp;'; 
      } 
     } 
    } 
//Render the target page number, but without it being a link 
$paginationCtrls .= ''.$pagenum.' &nbsp; &nbsp; '; 
//Render clickable number links that should appear on the right of the target page number 
for($i = $pagenum+1; $i <= $last; $i++){ 
    $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> &nbsp; &nbsp;'; 
    if($i >= $pagenum+4){ 
     break; 
    } 
} 
//This adds the same as above only checking if if we are on the last page and then generating Next 
if($pagenum != $last){ 
    $next = $pagenum + 1; 
    $paginationCtrls .= ' &nbsp; &nbsp; <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next &#187;</a> '; 
} 
} 
//Finish Pagination 

CSS代码:

div#pagination_controls a:active{ 
    border: 1px solid #C00; 
    background-color: #C00; 
    color: #3f3f3f; 
    border-radius: 2px; 
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px;} 

回答

2

你的活动页面不会呈现为一个链接。尝试改变这些行:

//Render the target page number, but without it being a link 
$paginationCtrls .= ''.$pagenum.' &nbsp; &nbsp; '; 

//Render the target page number, but without it being a link 
$paginationCtrls .= '<span class="active">'.$pagenum.'</span> &nbsp; &nbsp;'; 

div#pagination_controls a:active 
{ 
    border: 1px solid #C00; 
    background-color: #C00; 
    color: #3f3f3f; 
    border-radius: 2px; 
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px; 
} 

div#pagination_controls span.active 
{ 
    border: 1px solid #C00; 
    background-color: #C00; 
    color: #3f3f3f; 
    border-radius: 2px; 
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px; 
} 
+0

酷,它的工作原理,感谢帮助塔哈,花了一边看着它。 –

+0

不客气。 –