php get a get b,getB.php

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

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值