header('content-type:text/html;charset=utf-8');
session_start();
include_once "cus_check.php";
$sql = "select * from b where showHide = 1";
$result = mysqli_query($root,$sql);
$a['bContent'] = [];
$b = [];
$b['userPost'] = [];
$b['moreHref'] = '';
//存储板块所有信息
$c = []; //转存该板块用户发帖信息单元
date_default_timezone_set("PRC");
while($info = mysqli_fetch_array($result)){
$b['bId'] = $info['bId'];
$b['bName'] = $info['bTitle'];
$b['bContent'] = $info['bContent'];
$b['bPic'] = $info['bPic'];
if(isset($_SESSION['name']) and $_SESSION['name']){
$b['moreHref'] = 'b.php?bId='.$b['bId'];
}
else{
$b['moreHref'] = 'javascript:void(0)';
}
array_splice($b['userPost'],0,count($b['userPost'])); //清空一个数组,而不是去掉这个数组,该数组作为公共数组进行调用,应该在每一次进行初始化
//因为其他变量都在每一次变化,相当于每一次都已经初始化了,但他没有。
/如果用户没有投票的话是会那么userPost为空,没有长度,那么也迭代他自然也会出现错误
/// 如果清空$b的话,那么所有属性也将会被清空,没有发帖的话自然也会错误
/// 如果不做任何处理的话,userpost在第一次被赋值之后仍将保持上一次的值,那么下一次如果没有进行
$sql1 = "select p.tTitle,u.username,p.postTime,p.tContent from userinfo u,posttitle p where p.userId = u.userId and p.bId = ".$info['bId']." order by p.postTime desc limit 0,4";
$result1 = mysqli_query($root,$sql1);
while($info1 = mysqli_fetch_array($result1)){
$c['userName'] = $info1['username'];
$c['tTitle'] = $info1['tTitle'];
$c['postTime'] = date("Y-m-d H:i:s",$info1['postTime']);
$c['tContent'] = $info1['tContent'];
array_push($b['userPost'],$c);//每次push一条上去,这个公共数组必须保证是这个版块的调用,版块在变化?????
/Info并不会重用
}
array_push($a['bContent'],$b);
}
echo json_encode($a);
exit;
一键复制
编辑
Web IDE
原始数据
按行查看
历史