PHP头条
热点:

一个在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 "
  • \n";
    echo " ";
    if($self_id!=$id)
    echo "";
    echo $myrow[title];
    if($self_id!=$id)
    echo "";
    echo " - 【".$myrow[auth_name]."】 ".$myrow[add_time]." [id:$myrow][announce_id] 点击:$myrow[hit_count]] ($myrow[bytes] Bytes) ($myrow[return_count])\n";
    $query="select announce_id from announce where parent_id='$id' order by announce_id desc";
    $result=mysql_query($query,$dbconnect);
    echo "
      \n";
      while($myrow=mysql_fetch_array($result)){
      show_announce($myrow[announce_id],$self_id);
      }
      echo "
    \n";
    mysql_free_result($result);
    echo "
  • ";
    }
    ?>




    论坛内容




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

    www.phpzy.comtrue/phpyy/11794.htmlTechArticle一个在PHP中利用递归实现论坛分级显示的例子(为了简单起见,我将 /*存放帖子的表结构 CREATE TABLE announce ( announce_id int(11) NOT NULL auto_increment, board_id smallint(6) NOT NULL, title varchar(100) NOT N...

    相关文章

    相关频道:

    PHP之友评论

    今天推荐