Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > 一个在PHP中利用递归实现论坛分级显示的例子
【标  题】:一个在PHP中利用递归实现论坛分级显示的例子
【关键字】:PHP,论坛,HP,PHP
【来  源】:网络

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

Your Ad Here


<?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和js交互一例
  • 如何PHP的图形函数中显示汉字
  • 在PHP3中实现SESSION的功能
  • 如何用PHP实现文件上传例子
  • 实例学习PHP之投票程序篇
  • 为Windows 98设置本地PHP PERL开发
  • php中分页显示文章标题
  • PHP中的加密功能
  • PHP开发文件系统实例讲解
  • 两种php调用Java对象的方法
  • 【随机文章】
  • 客户端Cookie中文编程(2)
  • RedHat Linux 9打印机配置
  • Illustrator 裁剪标志制作与使用(1)
  • 优化带宽
  • 设置串行端口和调制解调器
  • Windows 的安全等级
  • LINUX环境线程编程个人经验
  • 也谈西直门桥的设计
  • 用会相应增加
  • 数据库系统工程师考试大纲(2004年新版)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.