【发布时间】:2017-03-09 09:20:56
【问题描述】:
我正在尝试创建一个 PHP api,我试图在其中检索新闻故事及其所有 cmets 并将其作为 json 发送。
这是我目前所拥有的:
$sql = "SELECT * FROM fb_clubnews WHERE clubid='$groupId' AND ori_newsid = 0 ORDER BY newsid DESC LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$storId = $row["newsid"];
$commentArray = array();
$wallAray[] = array("author"=>$row["userid"],
"story"=>$row["news"],
"date"=>$row["date"],
"time"=>$row["time"],
"matchid"=>$row["fk_match_id"],
"comments"=>$commentsArray);
}
}
我的问题是,我想避免在 sql 中创建 sql 并循环遍历它?!第二个内部 sql 将是:
$sql = "SELECT * FROM fb_clubnews WHERE ori_newsid = $storId ORDER BY newsid DESC";
如何让 $commentArray 填满 cmets。
我的 fb_clubnews 数据库结构如下所示:
int newsid (autoincrement),
int userid,
text news,
int data,
int time,
int matchid,
int ori_newsid
希望对此有所帮助,并在此先感谢 :-)
【问题讨论】:
-
分享数据库结构...那就更好的帮助.....
-
查看已编辑的问题
-
你的 cmets 表的结构是什么? cmets 存储在哪里?
-
我没有 cmets 表。主线故事和 cmets 都在同一张桌子上。如果故事的 ori_newsid > 0,则故事是评论。