有人在这里进行分页吗?我需要使用谷歌风格。没有ajax,jquery或javascript。只是简单的PHP
我在互联网上发现了不同的演示,但它有点不同。
我正在寻找的例子。
<< [1] 2 3 4 5>>
但是当我点击5
<< 3 4 [5] 6 7>>
有人能指出我这样的例子吗?
感谢
答案 0 :(得分:0)
这是分页...我希望这会对你有所帮助:)。
<table width="200" border="1" class="tbl_news_content" id="results">
<tbody>
<tr>
</tr>
<?php
$i=0;
$no=0;
$hal = $_GET['hal'];
if(!isset($_GET['hal']))
{
$page = 1;
}
else
{
$page = $_GET['hal'];
}
$max_show = 2;// this is the option that how many items do you want to show each page
$from = (($page * $max_show) - $max_show);
$query_banner = mysql_query("SELECT * FROM example_tbl ORDER BY ID DESC LIMIT $from,$max_show") or die(mysql_error());
while($show=mysql_fetch_array($query_banner))
{
$no++;
if(($no%2)==0)
$color = '#f2f2f2';
else
$color = '#f9f9f9';
?>
<tr class="rows" bgcolor="<?php echo $color; ?>">
<td class="no_content"><?php echo $no; ?></td>
<td class="banner_content"><?php echo $show['example']; ?></td>
<td class="action_content"></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div><!-- end of table_content -->
<div id="pagination">
<?php
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM example_tbl"),0);
$total_pages = ceil($total_results / $max_show);
echo "<center>";
if($hal > 1){
$prev = ($page - 1);
echo "<a href=$_SERVER[PHP_SELF]?hal=$prev>← Previous </a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($hal) == $i){
echo "$i ";
} else {
echo "<a href=$_SERVER[PHP_SELF]?hal=$i>$i</a> ";
}
}
// Build Next Link
if($hal < $total_pages){
$next = ($page + 1);
echo "<a href=$_SERVER[PHP_SELF]?hal=$next>Next →</a>";
}
echo "</center>";
?>
</div><!-- end of pagination -->