动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 一个在PHP中利用递归实现论坛分级显示的例子

作者来源: 
阅读 1228 人次 , 2006-3-29 4:11:00 


<?php
/*存放帖子的表结构
create table announce (
 announce_id int(11) not null auto_increment,
 board_id smallint(6) not null,
 title varchar(100) not null,
 content tinytext,
 add_time datetime default '0000-00-00 00:00:00' not null,
 auth_name varchar(20) not null,
 auth_mail varchar(40),
 hit_count smallint(6) not null,
 bytes mediumint(9) not null,
 parent_id tinyint(4) not null,
 auth_ip varchar(15) not null,
 top_id int(11) not null,
 return_count tinyint(4) not null,
 face char(3) not null,
 primary key (announce_id),
 key board_id (board_id),
 key top_id (top_id)
);
*/

function show_announce($id,$self_id){
global $dbconnect;
global $board_id;
$query="select * from announce where announce_id='$id'";
$result=mysql_query($query,$dbconnect);
$myrow=mysql_fetch_array($result);
mysql_free_result($result);
echo "<li>\n";
echo "<img src='images/mood".$myrow[face].".gif'> ";
if($self_id!=$id)
echo "<a href='show.php3?board_id=$board_id&announce_id=$myrow[announce_id]&top_id=$myrow[top_id]'>";
echo $myrow[title];
if($self_id!=$id)
echo "</a>";
echo " - <strong>【".$myrow[auth_name]."】</strong> ".$myrow[add_time]." <font color=darkblue>[id:$myrow][announce_id] 点击:$myrow[hit_count]]</font> ($myrow[bytes] bytes) <font color=red>($myrow[return_count])</font>\n";
$query="select announce_id from announce where parent_id='$id' order by announce_id desc";
$result=mysql_query($query,$dbconnect);
echo "<ul>\n";
while($myrow=mysql_fetch_array($result)){
show_announce($myrow[announce_id],$self_id);
}
echo "</ul>\n";
mysql_free_result($result);
echo "</li>";
}
?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>论坛内容</title>
<link rel="stylesheet" type="text/css" href="common.css">
</head>

<body>
<?php
//此处需要连接数据库
//可以根据需要加入分页
$query="select announce_id from announce where top_id='0' order by announce_id desc ";
$result_top=mysql_query($query,$dbconnect);
echo "<ul>\n";
while($myrow_top=mysql_fetch_array($result_top)){
show_announce($myrow_top[announce_id],0);
}
echo "</ul>\n";
mysql_free_result($result_top);
?>
</body>
</html>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:php和js交互一例
· 下一篇:PHP4中session的应用--欢迎页面
· 用PHP发送MIME邮件(六)
· PHP and UML Class Diagrams
· PHP中的加密功能
· PHP 编码规范(24)
· PHP-4.0.5的动作


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077