我在整個文檔中使用引導程序,我也將它用於分頁。減少引導程序分頁按鈕的長度
這個鏈接真棒:PHP & MySQL Pagination 它幫助我編寫了很多分頁方法(我使用postgre,我改變了一些東西)。
當我打印的分頁每個按鈕,我使用的引導代碼: http://www.w3schools.com/bootstrap/bootstrap_pagination.asp
<ul class=\"pagination pagination-sm\">$links</ul>
和:
$links .= ($i != $page) ? "<li><a href='$explode[0]$final$i'>$i</a><li> " : "";
爲串聯新的字符串到$第一個鏈接變量(當然然後回顯$鏈接)。
注:我使用爆炸(),因爲我得到我的地址,我解決了&page=
我的問題是:
如何縮短按鍵的數量每頁顯示的?
目前我的情況是截圖中的情況。 我很想得到這樣的:
[current][2][3][4][5]...[61][62]
編輯:
我改變了代碼,具有 「當前」:
if ($i != $page) {
$links.="<li><a href='$explode[0]$final$i'>$i</a><li>";
} else {
$links.="<li class=\"active\"><a href='#'>current</a><li>";
}
}
編輯:
第一個解決方案增加了新的圖像(它現在是黑色的,因爲我改變了主題與此同時)。
編輯:添加php代碼。
$perPage = addslashes(strip_tags(@$_GET["perPage"]));
$page = addslashes(strip_tags(@$_GET['page'])) ?: '1';
$startAt = $perPage * ($page - 1);
SWITCH ($direction){
case "SENT":
$count = "SELECT count(*) as total, 'SENT' as direction FROM sent WHERE date >= '$fdate' AND date <= '$tdate' AND identification LIKE '%$identification%' ";
$query = "SELECT *,'SENT' as direction FROM sent WHERE date >= '$fdate' AND date <= '$tdate' AND identification LIKE '%$identification%' ";
break;
}
$res = pg_fetch_assoc(pg_query($conn, $count));
$total = ceil($res['total']/$perPage);
if (empty($total1)) { $total1 = '0'; } else { $total1 = ceil($res['total1']/$perPage); }
$totalPages = $total + $total1;
$links = "";
$absolute_url = full_url($_SERVER);
for ($i = 1; $i <= $totalPages; $i++) {
$explode = explode("&page=", $absolute_url);
$final="&page=";
if ($i != $page) {
$links.="<li><a href='$explode[0]$final$i'>$i</a><li>";
} else {
$links.="<li class=\"active\"><a href='#'>current</a><li>";
}
}
$query .= "order by date DESC OFFSET '$startAt' LIMIT '$perPage' ";
$result = pg_query($conn, $query);
編輯: 發現在jQuery的問題: 它不會加載,從來沒有,但是當我調用該函數在文檔=就緒狀態,它會的。
<script>
$(document).ready(function(){
$('#paginateblock').css('margin-left','-110px');
});
</script>
我需要這總是工作,不僅在文檔是「準備」,而在對「paginateblock」或每次我換頁每一次點擊。
有人可以幫忙嗎?
解決方案#1: 由於小號Gandhe的幫助,爲我提供了他的代碼,我在這裏與我校複製它。
for ($i = 1; $i <= $totalPages; $i++) {
if($page >= 7){
$start = $page -4;
} else {
$start = $i;
}
$end = ($start + 7 < $totalPages)?($start + 7):$totalPages;
for ($start; $start <= $end ; $start++) {
$explode = explode("&page=", $absolute_url);
$final="&page=";
$css_class = ($page == $start) ? "class='active'" : "";
$links .= "<li><a href='$explode[0]$final$start'>$start</a><li>";
}
}
CSS: [爲<li>
的CSS並沒有改變]
#page-selection{
width:350px;
height:36px;
overflow:hidden;
}
HTML/PHP
<div id="page-selection"><?php echo "<ul class=\"pagination pagination-sm\">$links</ul>"; ?></div>
解決方案2 - 決賽: 我修改代碼多一點,頁碼按鈕位於<div>
之內,並且內容已對齊。 另外,頁面#1和#lastpage始終顯示。
CODE:
for ($i = 1; $i <= $totalPages; $i++) {
if($page >= 4){
$start = $page -3;
} else {
$start = $i;
}
$end = ($start + 6 < $totalPages)?($start + 6):$totalPages;
for ($start; $start <= $end ; $start++) {
$explode = explode("&page=", $absolute_url);
$final="&page=";
$css_class = ($page == $start) ? "class='active'" : "";
$links .= "<li><a href='$explode[0]$final$start'>$start</a></li>";
}
$firstpage = "<li><a href='$explode[0]$final'1><<</a></li>";
$lastpage = "<li><a href='$explode[0]$final$totalPages'>>></a></li>";
}
HTML:
<div id="page-selector">
<div class="page-selector-field"><?php echo "<ul class=\"pagination pagination-sm\">$firstpage</ul>"; ?></div>
<div id="page-selection" class="page-selector-field"><?php echo "<ul class=\"pagination pagination-sm\">$links</ul>"; ?></div>
<div class="page-selector-field"><?php echo "<ul class=\"pagination pagination-sm\">$lastpage</ul>"; ?></div>
</div>
CSS:
#page-selection{
width:344px;
height:36px;
overflow:hidden;
}
#page-selector{
width: 450px;
height:36px;
overflow:hidden;
/*margin: 0 auto; uncomment this if you want this bar centered */
}
.page-selector-field{
width:50px;
height:36px;
overflow:hidden;
float: left;
}
ul.pagination {
display: inline-block;
padding: 0;
margin: 0;
}
ul.pagination li {
display: inline;
width: 50px;
}
ul.pagination li a {
display: block;
width: 50px;
text-align:center;
float: left;
padding: 8px 16px;
text-decoration: none;
}
您能澄清一下您想要顯示的鏈接嗎?如果當前鏈接不是第一個呢?如果您不想顯示所有鏈接,請不要遍歷所有可能的頁面。 –
當我截圖時,我在第54頁(你會注意到它缺失)。取而代之的是,我會將其改爲現在,這很容易。其餘的我需要幫助。我沒有想到一種方法來「不循環所有,一次只打印7頁」,或「循環所有,但一次只顯示X頁」假設 – Nihvel
這不是引導程序問題,您需要修改你的PHP代碼只輸出你想要的頁數。請包括用頁面生成數組的php代碼。 – mauriblint