whileループ内のコメントをnewsfeed_id
で取得しようとしていますが、最初の反復後に結果が表示されません。私は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まだ1つのレコードしか表示しようとしていませんでした –
nf_status = 1には多くの行が含まれているとします。あなたは '$ NewsfeedRes [] = $ rowNews;'を必要とせず、 'cmt.cmt_commentをコメント'として選択します。 –