我正在处理网站分页,我正在使用以下代码。
<tr>
<td class="nex_pre" colspan="3"> <?php
$query="select * from prosummary";
$query="select * from prosummary";
$result=mysqli_query($connect,$query);
$count=mysqli_num_rows($result);
$pages=ceil($count/10);
for($i=1;$i<=$pages;$i++) { ?>
<a href="productmanager.php?p=<?php echo $i; ?>">
<?php echo $i;?></a>
<?php } ?>
</td>
</tr>
输出显示如下: -
1 2 3 4 5
但我想显示这样的输出: -
[First] [1] [2] [3] [4] [5] . . . . [10] [11] [12] [13] [14] [Last]
答案 0 :(得分:0)
只需用你需要的任何字符串连接$ i:
类似的东西:
<a href="productmanager.php?p=<?php echo $i; ?>">
<?php echo $i==1 ? "[FIRST]" : $i==$pages ? "[LAST]" : "[".$i."]";?></a>
<?php } ?>
答案 1 :(得分:0)
您好请检查以下代码
<tr>
<td class="nex_pre" colspan="3"> <?php
$query="select * from prosummary";
$query="select * from prosummary";
$result=mysqli_query($connect,$query);
$count=mysqli_num_rows($result);
$pages=ceil($count/10);
$j=1;
for($i=1;$i<=$pages;$i++) {
if($pages==1 || $j==1){ ?>
<a href="productmanager.php?p=<?php echo $i; ?>">First</a>
<?php }else if($pages==$i){ ?>
<a href="productmanager.php?p=<?php echo $i; ?>">Last</a>
<?php }else{ ?>
<a href="productmanager.php?p=<?php echo $i; ?>"> <?php echo $i;?></a>
<?php }?>
<?php $j++; } ?>
</td>
</tr>
答案 2 :(得分:0)
试着希望它能为你效用
<div style="padding: 10px;">
<?php
$query = "select * from table_name ";
$result = mysqli_query($link, $query);
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
echo "<center><a href='index.php?page=1' style='padding:10px;'>".'First Page'."</a>";
$skipped = false;
for ($i = 1; $i <= $total_pages; $i++) {
if ($i < 3 || $total_pages- $i < 3 || abs($page - $i) < 3) {
if ($skipped)
echo '<span> ... </span>';
$skipped = false;
echo "<a href='index.php?page=" . $i . "' style='padding:5px;'>" . $i . "</a>";
} else {
$skipped = true;
}
}
echo "<a href='index.php?page=$total_pages' style='padding:10px;'>".'Last Page'."</a></center>";
?>