我試圖通過newsfeed_id
來獲取while循環中的註釋,但它在第一次迭代後不顯示任何結果。我print_r
動態生成查詢其工作正常,但結果不顯示。爲什麼while循環在while循環內第一次迭代後沒有顯示結果?
$NewsfeedRes = array();
$Newsfeed = "select * from `ws_newsfeed` where `nf_status` = 1";
$NewsfeedQuery = mysqli_query($this->connection,$Newsfeed);
while($rowNews = mysqli_fetch_assoc($NewsfeedQuery)){
$NewsfeedRes[] = $rowNews;
$PushComment = "SELECT cmt.`cmt_id`,cmt.`cmt_comment`,cmt.`date_added`,
us.`u_username`,us.`u_image`
FROM `ws_comments` AS cmt
LEFT JOIN `ws_user` AS us ON cmt.`u_id`=us.`u_id`
WHERE cmt.`cmt_target_id` = ".$rowNews['nf_id']."
AND cmt.`cmt_table_name`='ws_newsfeed'";
//echo $PushComment; This giving me correct query
$PushCommentQuery = mysqli_query($this->connection,$PushComment);
while($rowPComment = mysqli_fetch_assoc($PushCommentQuery)){
$NewsfeedRes['comments'] = $rowPComment;
}
}
$output = array(
'NewsfeedRes' => $NewsfeedRes,
);
echo json_encode($output, JSON_PRETTY_PRINT);
任何人都可以指導我哪裏我錯了,我可以解決這個問題。我會感激。謝謝
'$ newid = $ rowNews ['nf_id'];'並且在語句中使用''newsid''。 –
@MawiaHL我仍然只顯示一條記錄 –
假設nf_status = 1包含很多行。你不需要'$ NewsfeedRes [] = $ rowNews;'並選擇'cmt.cmt_comment as comments'。 –