请求再次帮忙修改一下同段PHP代码!万分感谢!
用以代码作为蓝本,分别设计一张外页(命名为index.php)和一张内页(命名为detail.php)。1.)内页的分页方式是一条数据一页,就是说每一张内页仅仅显示一条数...
用以代码作为蓝本,分别设计一张外页(命名为index.php)和一张内页(命名为detail.php)。
1.)内页的分页方式是一条数据一页,就是说每一张内页仅仅显示一条数据,即<a href='$url'>$name</a> ;
2.)外页显保持现在的5行6列共30条链接数据,但只读取name 这一个字段,其原来url字段部分替换为每一张内页的相应链接,每一
条链接的形式:<a href='detail.php?page=ID'>$name</a>。
我的描述不知道能不能让您明白!
-------------------------------------------------------
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or
die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
$perpagenum = 30;//定义每页显示几条
$total = mysql_fetch_array(mysql_query("select count(*) from link2"));//查询数据库中一共有多少条数据
$Total = $total[0]; //
$Totalpage = ceil($Total/$perpagenum);//上舍,取整
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//page可能的四种状态
{
$page=1;
}
else
{
$page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
}
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "select * from link2 order by id desc limit $startnum,$perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$contents = mysql_fetch_array($rs);
if($total)//如果$total不为空则执行以下语句
{
$sql = "select * from link2 order by id desc limit $startnum, $perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$nums = 0;
echo '<table>';
while ($contents = mysql_fetch_array($rs)){
$url = $contents['url'];
$name = $contents['name'];
if ($nums%5==0) echo '<tr>';
$nums++;
echo "<td><a href='$url'>$name</a></td>";
}
echo '</table>';
mysql_free_result($rs);
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "<center>共有".$Total."条记录,每页".$perpagenum."条,共".$Totalpage."页 ";
if($page != 1)
{
echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'> 下一页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$Totalpage."'> 尾页</a></center>";
}
}
else //如果$total为空则输出No message
{
echo "<center>No message</center>";
}
?> 展开
1.)内页的分页方式是一条数据一页,就是说每一张内页仅仅显示一条数据,即<a href='$url'>$name</a> ;
2.)外页显保持现在的5行6列共30条链接数据,但只读取name 这一个字段,其原来url字段部分替换为每一张内页的相应链接,每一
条链接的形式:<a href='detail.php?page=ID'>$name</a>。
我的描述不知道能不能让您明白!
-------------------------------------------------------
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or
die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
$perpagenum = 30;//定义每页显示几条
$total = mysql_fetch_array(mysql_query("select count(*) from link2"));//查询数据库中一共有多少条数据
$Total = $total[0]; //
$Totalpage = ceil($Total/$perpagenum);//上舍,取整
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage)//page可能的四种状态
{
$page=1;
}
else
{
$page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
}
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "select * from link2 order by id desc limit $startnum,$perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$contents = mysql_fetch_array($rs);
if($total)//如果$total不为空则执行以下语句
{
$sql = "select * from link2 order by id desc limit $startnum, $perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$nums = 0;
echo '<table>';
while ($contents = mysql_fetch_array($rs)){
$url = $contents['url'];
$name = $contents['name'];
if ($nums%5==0) echo '<tr>';
$nums++;
echo "<td><a href='$url'>$name</a></td>";
}
echo '</table>';
mysql_free_result($rs);
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "<center>共有".$Total."条记录,每页".$perpagenum."条,共".$Totalpage."页 ";
if($page != 1)
{
echo "<a href='".$_SERVER['PHP_SELF']."'>首页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$per."'> 上一页</a>";
}
if($page != $Totalpage)
{
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$next."'> 下一页</a>";
echo "<a href='".$_SERVER['PHP_SELF'].'?page='.$Totalpage."'> 尾页</a></center>";
}
}
else //如果$total为空则输出No message
{
echo "<center>No message</center>";
}
?> 展开
2009-04-06
展开全部
index.php 修改为:
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
$sql = "select count(*) from link2";//查询数据库中一共有多少条数据
$rs = mysql_query($sql);
list($Total) = mysql_fetch_array($rs);
mysql_free_result($rs);
if($Total)//如果$total不为空则执行以下语句
{
$perpagenum = 30;//定义每页显示几条
$Totalpage = ceil($Total/$perpagenum);//上舍,取整乱汪
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage) $page=1; //page可能的四种状态
else $page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "select id,name from link2 order by id desc limit $startnum, $perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$nums = 0;
echo '<table>';
while ($contents = mysql_fetch_array($rs)){
$id = $contents['id'];
$name = $contents['name'];
if ($nums%5==0) echo '<tr>';
$nums++;
echo "<td><a href='detail.php?id=$id'>$name</a></td>";
}
echo '</table>';
mysql_free_result($rs);
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "<center>共有 $Total 条记录,每页 $perpagenum 条,共 $Totalpage 页 ";
$self=$_SERVER['PHP_SELF'];
if($page != 1)
{
echo "<a href='$self'>首页</a> ";
echo "<a href='$self?page=$per'>上一页</a> ";
}
if($page != $Totalpage)
{
echo "<a href='$self?page=$next'>下一页</a> ";
echo "<a href='$self'?page=$Totalpage'>尾页</a></center>";
}
}
else 亩陪岁//如果$total为 0 则输出No message
{
echo "<center>No message</center>";
}
?>
新写的detail.php为:
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
if($isset($_GET['id']))//检测是否直接打开
{
$sql = "select url,name from link2 where id={$_GET['id']}";
$rs = mysql_query($sql);
list($url,$name) = mysql_fetch_array($rs);
mysql_free_result($rs);
echo "<table align=center><tr><td><a href='$url'>$name</a></td></tr></table>";
}
else
{
echo 迅睁"<center>本页面不运行直接打开。</center>";
}
?>
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
$sql = "select count(*) from link2";//查询数据库中一共有多少条数据
$rs = mysql_query($sql);
list($Total) = mysql_fetch_array($rs);
mysql_free_result($rs);
if($Total)//如果$total不为空则执行以下语句
{
$perpagenum = 30;//定义每页显示几条
$Totalpage = ceil($Total/$perpagenum);//上舍,取整乱汪
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage) $page=1; //page可能的四种状态
else $page=$_GET['page'];//如果不满足以上四种情况,则page的值为$_GET['page']
$startnum = ($page-1)*$perpagenum;//开始条数
$sql = "select id,name from link2 order by id desc limit $startnum, $perpagenum";//查询出所需要的条数
$rs = mysql_query($sql);
$nums = 0;
echo '<table>';
while ($contents = mysql_fetch_array($rs)){
$id = $contents['id'];
$name = $contents['name'];
if ($nums%5==0) echo '<tr>';
$nums++;
echo "<td><a href='detail.php?id=$id'>$name</a></td>";
}
echo '</table>';
mysql_free_result($rs);
$per = $page - 1;//上一页
$next = $page + 1;//下一页
echo "<center>共有 $Total 条记录,每页 $perpagenum 条,共 $Totalpage 页 ";
$self=$_SERVER['PHP_SELF'];
if($page != 1)
{
echo "<a href='$self'>首页</a> ";
echo "<a href='$self?page=$per'>上一页</a> ";
}
if($page != $Totalpage)
{
echo "<a href='$self?page=$next'>下一页</a> ";
echo "<a href='$self'?page=$Totalpage'>尾页</a></center>";
}
}
else 亩陪岁//如果$total为 0 则输出No message
{
echo "<center>No message</center>";
}
?>
新写的detail.php为:
<?php
mysql_connect("localhost", "dat1011", "Pass123456") or die("Could not connect: " . mysql_error());
mysql_select_db("dat1011");
if($isset($_GET['id']))//检测是否直接打开
{
$sql = "select url,name from link2 where id={$_GET['id']}";
$rs = mysql_query($sql);
list($url,$name) = mysql_fetch_array($rs);
mysql_free_result($rs);
echo "<table align=center><tr><td><a href='$url'>$name</a></td></tr></table>";
}
else
{
echo 迅睁"<center>本页面不运行直接打开。</center>";
}
?>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询