设为首页   加入最爱           最新更新:全方位英文文章资料库
 
资料坊搜索: 标题 全文     
一个在PHP中利用递归实现论坛分级显示的例子
   首页>>YesizeCOM>>电脑技能坊>>PHP>>正文       
 
广告招租,e-mail:yesize@hotmail.com

广告招租,e-mail:yesize@hotmail.com


<?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>


上一篇:PHP4中session的应用--欢迎页面 下一篇:php和js交互一例

版权说明:作品来源于网上,版权归作者所有,如果无意中侵犯了您的版权,请来信告知,本站将在3个工作日内删除。yesize@hotmail.com
  热门小游戏分类 
射击小游戏 连连看小游戏
台球小游戏 成人小游戏
CS小游戏 化妆小游戏
赛车小游戏 休闲小游戏
篮球小游戏 换装小游戏
儿童小游戏 牛牛小游戏
麻将小游戏 冒险小游戏
美媚小游戏 益智小游戏
体育小游戏  
Society Recreation & Sports
Travel & Leisure Communications
Vehicles Computers
Fashion Arts & Entertainment
Reference & Education Disease & Illness
Writing & Speaking Politics
Product Reviews Food & Beverage
Finance Internet Business
Self Improvement Home & Family
Health & Fitness Business
最新更新内容
警惕“公务员报考热”背
公务员考试不是丈母娘考
一名新公务员的自白:我
公务员考脑筋急转弯与挂
北努斗:2006行政能力测
大讨论:06行测BT题目大
过来人回忆:当年,我也
一家之言:公务员热折射
公务员考试申论要是有正
数十万大学生走进公务员
      粤ICP备05005424         Copyright ©2000 - 2004 Yesize.COM