php与mysql 分页 选页码跳转不了 页码太长 怎么缩短啊 20
<?phprequire('dbconnect.php');?><?$result=mysql_query("selectidfromaa");$num=mysql_nu...
<?php
require('dbconnect.php');
?>
<?
$result=mysql_query("select id from aa");
$num=mysql_num_rows($result);
$page_size=4;
if($num<=$page_size){
$page_count=1;
}
if($num%$page_size)
{
$page_count=(int)($num/$page_size)+1;
}
else {
$page_count=$num/$page_size;
}
if(isset($_GET[page]))
{
$page=(int)($_GET[page]);
}
else {
$page=1;
}
echo " <table width=64% border=1 bgcolor=#66CCFF align=center>";
echo "<tr><td colspan=9 align=center>
修改新闻</td>
</tr>";
echo "<tr><td align=center width=15% >
标题</td>";
echo"<td align=center width=15%>
内容</td>";
echo"<td align=center width=15%>
发布时间</td>";
echo"<td align=center width=15%>
编辑</td></tr>";
$qq=mysql_query("select * from aa limit ".($page-1)*$page_size .", $page_size");
while($row=mysql_fetch_array($qq))
{
$row[title]=substr($row[title],0,10). "...";
$row[content]=substr($row[content],0,26) . "...";
$len=strlen($row[content]);
echo "<tr><td align=center>$row[title]($len 字节)</td>";
echo "<td align=center>$row[content]</td>";
echo "<td align=center>$row[time]</td>";
echo "<td align=center><a href='xiugai.php?id=$row[id]')'><font size=4>修改</font></a> <a href='shanchu.php?id=$row[id]')'><font size=4>删除</font></a></td></tr>";
}
echo "</table>";
?>
<br>
<br>
<br>
<br>
<br>
<br>
<?
echo "<tr><td align=center><table width='100%'><tr><td align=center>";
// 如果页数大于1,列出所有页数
$first=1;
$aa=$page-1;
$ss=$page+1;
$last=$page_count;
if($page!=$first)
{
echo "<a href='?page=".$first."'>首页</a> ";
echo "<a href='?page=".$aa."'>上一页</a>";
}
for($i=1;$i<=$page_count;$i++){
if($i==$page){
echo "$i ";
}
else {
$i=substr($i,0,10) . "...";
echo "<a href='?page=".$i."'>$i </a>";
}
}
$first=1;
$aa=$page-1;
$ss=$page+1;
$last=$page_count;
if($page!=$page_count){
echo "<a href='?page=".$ss."'>下一页 </a>";
echo "<a href='?page=".$last."'>尾页</a>";
}
echo " 第 $page 页 ";
echo " 共 $page_count 页";
echo "第 <a href='?page=".$page."'><input type=text name='$page' size=2></a> 页";
echo "<input type=submit value=跳转>";
?> 展开
require('dbconnect.php');
?>
<?
$result=mysql_query("select id from aa");
$num=mysql_num_rows($result);
$page_size=4;
if($num<=$page_size){
$page_count=1;
}
if($num%$page_size)
{
$page_count=(int)($num/$page_size)+1;
}
else {
$page_count=$num/$page_size;
}
if(isset($_GET[page]))
{
$page=(int)($_GET[page]);
}
else {
$page=1;
}
echo " <table width=64% border=1 bgcolor=#66CCFF align=center>";
echo "<tr><td colspan=9 align=center>
修改新闻</td>
</tr>";
echo "<tr><td align=center width=15% >
标题</td>";
echo"<td align=center width=15%>
内容</td>";
echo"<td align=center width=15%>
发布时间</td>";
echo"<td align=center width=15%>
编辑</td></tr>";
$qq=mysql_query("select * from aa limit ".($page-1)*$page_size .", $page_size");
while($row=mysql_fetch_array($qq))
{
$row[title]=substr($row[title],0,10). "...";
$row[content]=substr($row[content],0,26) . "...";
$len=strlen($row[content]);
echo "<tr><td align=center>$row[title]($len 字节)</td>";
echo "<td align=center>$row[content]</td>";
echo "<td align=center>$row[time]</td>";
echo "<td align=center><a href='xiugai.php?id=$row[id]')'><font size=4>修改</font></a> <a href='shanchu.php?id=$row[id]')'><font size=4>删除</font></a></td></tr>";
}
echo "</table>";
?>
<br>
<br>
<br>
<br>
<br>
<br>
<?
echo "<tr><td align=center><table width='100%'><tr><td align=center>";
// 如果页数大于1,列出所有页数
$first=1;
$aa=$page-1;
$ss=$page+1;
$last=$page_count;
if($page!=$first)
{
echo "<a href='?page=".$first."'>首页</a> ";
echo "<a href='?page=".$aa."'>上一页</a>";
}
for($i=1;$i<=$page_count;$i++){
if($i==$page){
echo "$i ";
}
else {
$i=substr($i,0,10) . "...";
echo "<a href='?page=".$i."'>$i </a>";
}
}
$first=1;
$aa=$page-1;
$ss=$page+1;
$last=$page_count;
if($page!=$page_count){
echo "<a href='?page=".$ss."'>下一页 </a>";
echo "<a href='?page=".$last."'>尾页</a>";
}
echo " 第 $page 页 ";
echo " 共 $page_count 页";
echo "第 <a href='?page=".$page."'><input type=text name='$page' size=2></a> 页";
echo "<input type=submit value=跳转>";
?> 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询