ریحانه محبوب
سه شنبه 03 تیر 1393, 11:12 صبح
سلام دوستان خسته نباشید
من برای سایتم یه صفحه بندی معمولی ایجاد کردم این کد رو نوشتم
<?php
if($pages)
{
print "صفحه: ";
for($i=1;$i<=$pages;$i++)
{
print "<a href='?page=$i'>$i</a>";
}
}
?>
و به این صورت نشون داده می شه
120445
حالا می خوام به یکی از این دو تا شکل زیر در بیارمش
باید چه شرطی به این کد اضافه کنم که دکمه شروع و پایان و قبلی و بعدی رو نشون بده؟
اگه راهنمایی کنید ممنون می شم
120446
aalmair
سه شنبه 03 تیر 1393, 12:22 عصر
header("Content-Type: text/html; charset=utf-8");
function pagination($currect_page=0,$affected_row=0,$max_ro w=0,$next_link_url=''){
$str='';
$n_link='';
if($next_link_url){
$n_link=$next_link_url.'&';
}
$str.='<div style="margin-top:30px" dir=ltr>';
$str.='<div style="text-align:center;"><span style="border:#8000ff solid 1px;" dir=rtl> '.(int)(ceil($affected_row/$max_row)).' صفحه ، '.$affected_row.' نتیجه</span></div>';
$str.='<div class="pagination">';
if($currect_page>1){
$str.="<a href='?".$n_link."start=".($currect_page-1)."' class=previous_page>← Previous</a>";
}else{
$str.='<span class="disabled previous_page">← Previous</span>';
}
if($currect_page>1){
$str.="<a href='?".$n_link."start=1' class=previous_page>← First</a>";
}else{
$str.='<span class="disabled previous_page">← First</span>';
}
$start_page=($currect_page>=1&&$currect_page<=5)?1 :$currect_page-5;
for($i=0;$i<10&&($max_row*$start_page)<$affected_row+$max_row;$i++,$start_page++){
if($start_page==$currect_page){
$str.= "<em class=current>$start_page</em>" ;
}else{
$str.= "<a href='?".$n_link."start=$start_page'>$start_page</a>" ;
}
}
if(($currect_page)*$max_row<$affected_row){
$str.="<a href='?".$n_link."start=".($currect_page+1)."' rel=next class=next_page>Next →</a>";
}else{
$str.="<span rel=next class='disabled next_page'>Next →</span>";
}
if(($currect_page)*$max_row<$affected_row){
$str.="<a href='?".$n_link."start=".((int)(($affected_row+$max_row-1)/$max_row))."' rel=next class=next_page>Last →</a>";
}else{
$str.="<span rel=next class='disabled next_page'>Last →</span>";
}
$str.="</div></div>";
return $str;
}
echo '<style>.pagination {
clear:left;font:18px serif,sans-serif;
text-align: center;
padding: 0.3em;
cursor: default; }
.pagination a, .pagination span, .pagination em {
padding: 0.2em 0.5em; }
.pagination .disabled {
color: #aaaaaa; }
.pagination .current {
font-style: normal;
font-weight: bold;
color: #ff00c7; }
.pagination a {
border: 1px solid #dddddd;
color: #8000ff;
text-decoration: none; }
.pagination a:hover, .pagination a:focus {
border-color: #003366;
background: #8000ff;
color: white; }
.pagination .previous_page, .pagination .next_page {
border-width: 2px; }
.pagination .previous_page {
margin-right: 1em; }
.pagination .next_page {
margin-left: 1em;
}</style>';
if(isset($_GET['start'])&&is_numeric($_GET['start'])&&$_GET['start']>"0"){
$currect_page=(int)$_GET['start'];
}else{
$currect_page=1;
}
$max_row=10;
$all_resualt=200;
echo pagination($currect_page,$all_resualt,$max_row);
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.