两级结构变成N级结构

i_num 2011-08-15 04:40:54
<?php

require_once ('../../global.php');
require_once ('json.class.php');


header("Content-type: application/json; charset=UTF-8 ");
if($_SERVER['REQUEST_METHOD']=="GET") {

$httpZid = $_SERVER['HTTP_ZID'];
$getZid=$_GET['zid'];

$Zid =$httpZid!=NULL||$httpZid!=""?$httpZid:($getZid!=NULL||$getZid!=""?$getZid:0);

$sqlwhere="";
if ($Zid==0||$Zid==""||$Zid==NULL){//未传参数获取所有主版块信息
$sqlwhere=" and f.type='category'";


}elseif ($Zid>0) {//获取fid主版块下的子版块信息
$sqlwhere=" and f.fup='$Zid'";

}



$query = $db->query("SELECT f.fid,f.name,f.type,f.childid,f.fup,f.logo,f.descrip,f.metadescrip,f.forumadmin,f.across,f.allowhtm,f.password,f.allowvisit,f.showsub,f.ifcms,fd.tpost,fd.topic,fd.article,fd.subtopic,fd.top1,fd.lastpost FROM pw_forums f LEFT JOIN pw_forumdata fd USING(fid) WHERE f.ifsub='0' AND f.ifcms!=2 $sqlwhere ORDER BY f.vieworder");


$zjson['list']=array();
while ($forums = $db->fetch_array($query)) {
$fid=$forums['fid'];//FID
$name= iconv( "gb2312","utf-8",$forums['name']);//版块名称
$tpost=$forums['tpost'];//新帖子数
$topic=$forums['topic'];//主题数
$article=$forums['article'];//帖子数
$postsCountnum=20;//主题分页
$replyCountnum=20;//帖子分页
$sumpage=$topic/$postsCountnum;
$sumpage=(int)($sumpage+1);

if ($Zid==0||$Zid==""||$Zid==NULL){
$platearray = array("zid" => "$fid","Name" => "$name");
}elseif ($Zid>0) {
$platearray = array("fid" => "$fid","Name" => "$name","threads" => "$topic","posts" => "$article","todayposts" => "$tpost","sumpage" => "$sumpage","postsCountnum" => "$postsCountnum","replyCountnum" => "$replyCountnum");
}
array_push($zjson['list'],$platearray);

}

echo $json_stringen = Json::encode($zjson);

//echo json_encode($zjson);
}else {

echo "{\"error\":1}";
}





?>
...全文
57 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Framework
创建于2008-08-27

4245

社区成员

国内外优秀PHP框架讨论学习
申请成为版主
帖子事件
创建了帖子
2011-08-15 04:40
社区公告
暂无公告