我有一条消息要发布,如果我发布了一条消息,那么其他人可以对我的消息发表评论,但是现在我得到的输出就像一条帖子中有3条评论,然后我得到的是,每条评论获得3条相同的消息。
表结构如下
event table
ev_id ev_name ev_user
1 ABC MN
2 XYZ AB
3 PQR EF
comment table
co_event_id co_name co_comment
1 QR Some Comment
1 ST Some Comment
2 UV Some Comment
$Query = "SELECT event.*, comment.* FROM event LEFT JOIN comment ON event.ev_id = comment.co_event_id";
$Result = $con->query($Query);
while ($row = $Result->fetch(PDO::FETCH_ASSOC)) {
$res[$row["ev_id"]]['ev_id'] = $row["ev_id"];
$res[$row["ev_id"]]['ev_name'] = $row["ev_name"];
$res[$row["ev_id"]]['ev_user'] = $row["ev_user"];
$res[$row["ev_id"]]['comment'][] = array(
"co_event_id" => $row['co_event_id'],
"co_name" => $row['co_name'],
"co_comment" => $row['co_comment']
);
}