小型bbs论坛系统开发9 前台父板块列表页

<?php  
include_once './inc/tool.inc.php';
include_once './inc/config.inc.php';
include_once './inc/mysql.inc.php';
include_once './inc/page.inc.php';
// 初始化网站标题/css
$webTitle = '父板块列表页';
$cssArray[] = 'public.css';
$cssArray[] = 'list.css';
//获取数据库连接
$link = sql_connect();
//验证登录状态
if(!$member_id=is_login($link)){
    skip('login.php?url=index.php','error','请先登录!');
}
//验证父板块id是否合法,此处有个bug
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
    skip('index.php','error','该父板块不存在!');
}
?>

<?php include_once './inc/header.inc.php'; ?>
<!-- 正文内容 -->
    <?php 
    $query = "select * from sfk_father_module order by sort asc";
    $result_father = sql_execute($link,$query);

    $father_id_flag = -1;//验证父板块id是否存在的初始化变量
    $moduleListHtml = "";//所有版块列表html代码的初始化变量
    //获取所有父版块
    while($data_father = mysqli_fetch_assoc($result_father)){
        //如果取到当前父板块id
        if($data_father['id'] == $_GET['id']){
            //获取当前父板块名称
            $father_name = $data_father['module_name'];
            $query = "select * from sfk_son_module order by sort asc";
            $result_this_son = sql_execute($link,$query);
            $sonIdCollection = '-1,';//所有当前父板块下子版块的id集合的初始化变量
            $father_id_flag = 1;
            while($data_this_son = mysqli_fetch_assoc($result_this_son)){
                if($data_this_son['father_module_id'] == $_GET['id']){
                    //获取当前父板块下所有子版块的名称
                    $data_this_son_name[] = $data_this_son['module_name'];
                    //获取当前父板块下所有子版块的id集合
                    $sonIdCollection .= $data_this_son['id'].',';
                }
            }

        }
        //获取所有子版块
        $sonListHtml = "";//所有子版块列表html代码的初始化变量
        $query = "select * from sfk_son_module where father_module_id = {$data_father['id']}";
        $result_son = sql_execute($link,$query);
        while($data_son = mysqli_fetch_assoc($result_son)){
            //实际子版块列表html代码
            $sonListHtml .="<ul><li><h3><a href='#'>{$data_son['module_name']}</a></h3></li></ul>"; 
        }
        //实际所有版块列表html代码
        $moduleListHtml .= "<li>
                                <h2>
                                    <a href='list_father.php?id={$data_father['id']}'>
                                        {$data_father['module_name']}
                                    </a>
                                </h2>{$sonListHtml}
                            </li>";
    }
    if($father_id_flag < 0){
        skip('index.php','error','父板块id不存在!');
    }


    $sonIdCollection = rtrim($sonIdCollection,',');//处理子版块id集合前后的逗号。
    //获取当前父板块下所有子版块的今日发帖总数
    $query = "select count(*) from sfk_content where module_id in ({$sonIdCollection}) and time > curdate()";
    $countToday = sql_num($link,$query);
    //获取当前父板块下所有子版块的历史发帖总数
    $query = "select count(*) from sfk_content where module_id in ({$sonIdCollection})";
    $countAll = sql_num($link,$query);
    ?>

    <div id="position" class="auto">
         <a href = 'index.php'>首页</a> &gt; 
         <a href = "list_father.php?id={$_GET['id']}"><?php echo $father_name; ?></a>
    </div>
    <div id="main" class="auto">
        <div id="left">
            <div class="box_wrap">
                <h3><?php echo $data_father['module_name']; ?></h3>
                <div class="num">
                    今日:<span><?php echo $countToday; ?></span>&nbsp;&nbsp;&nbsp;
                    总帖:<span><?php echo $countAll; ?></span>
                    <div class="moderator"> 
                        子版块: 
                        <?php 
                        if(isset($data_this_son_name)){
                            foreach ($data_this_son_name as $value){ 
                                echo "<a href = '#'>$value</a>&nbsp;";
                            }
                        }
                        ?>
                    </div>
                </div>
                <div class="pages_wrap">
                    <a class="btn publish" href=""></a>
                    <div class="pages">
                    <?php 
                    $data = page($countAll,3,5);
                    echo $data['html'];
                    ?>
                    </div>
                    <div style="clear:both;"></div>
                </div>
            </div>
            <div style="clear:both;"></div>
            <ul class="postsList">
                <!-- 帖子列表区域 -->
                <?php 
                /*多表查询当前父板块下的用户名、帖子标题、帖子id、帖子发布时间、所属子版块、头像、浏览次数。
                连接条件:
                    1/包含在当前父板块下的所有子版块;
                    2/帖子表包含的板块id与子版块的某个id一致;
                    3/帖子表包含的用户id与用户表的某个id一致。
                避免笛卡尔集
                尚未对最后回复时间、回复做出查询。
                */
                $query = "select s_m.username,s_c.title,s_c.time,s_s_m.module_name,s_m.photo,s_c.times 
                          from sfk_content s_c,sfk_member s_m,sfk_son_module s_s_m
                          where module_id in ({$sonIdCollection})
                          and s_c.module_id = s_s_m.id
                          and s_c.member_id = s_m.id {$data['limit']}";
                $result_content = sql_execute($link,$query);
                while($data_content = mysqli_fetch_assoc($result_content)){

                ?>
                <li>
                    <div class="smallPic">
                        <a href="#">
                            <img width="45" height="45" src="<?php 
                            if($data_content['photo'] != ''){
                                echo $data_content['photo'];
                            }else{
                                echo 'style/photo.jpg';
                            }?>"
                            >
                        </a>
                    </div>
                    <div class="subject">
                        <div class="titleWrap">
                            <a href="#">[<?php echo $data_content['module_name'] ?>]</a>&nbsp;&nbsp;
                            <h2><a href="#"><?php echo $data_content['title'] ?></a></h2>
                            </div>
                        <p>
                            楼主:<?php echo $data_content['username'] ?>&nbsp;
                            发表于:<?php echo $data_content['time'] ?>&nbsp;
                            最后回复:2014-12-08&nbsp;
                        </p>
                    </div>
                    <div class="count">
                        <p>
                            回复<br /><span>41</span>
                        </p>
                        <p>
                            浏览<br /><span><?php echo $data_content['times'] ?></span>
                        </p>
                    </div>
                    <div style="clear:both;"></div>
                </li>
                <?php } ?>
                <!-- 帖子列表区域 结束-->
            </ul>
            <!-- <div class="pages_wrap">
                <a class="btn publish" href=""></a>
                <div class="pages">
                    <a>« 上一页</a>
                    <a>1</a>
                    <span>2</span>
                    <a>3</a>
                    <a>4</a>
                    <a>...13</a>
                    <a>下一页 »</a>
                </div>
                <div style="clear:both;"></div>
            </div> -->
        </div>
        <div id="right">
            <div class="classList">
                <div class="title">版块列表</div>
                <ul class="listWrap">
                <?php 

                echo $moduleListHtml;
                ?>

                </ul>
            </div>
        </div>
        <div style="clear:both;"></div>
    </div>



<!-- 正文结束 -->

<?php include_once './inc/footer.inc.php'; ?>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值