Hello guys i currently have a MySQL query that works perfectly fine, but the only thing i don't like is that when I get returned data, some rows come duplicated except for the last column of the row .
I guess the reason why is because when I'm selecting everything including the left join, the commenttext
column contains the data for a post submitted by a user.
For example) If I post a post with id of 1 and 5 people comment on that post MySQL query will bring up 5 rows with all the data in every column the same except for the last column containing the different comment pertaining to the post.
So far here is my MySQL query. How can I make it where it doesn't bring back duplicated data but only the comments grouped with the id of the post or how can i store all the comments to an array so when I run a foreach loop I can then run the comments array inside with a while loop. The reason I would use a foreach loop is to export the data with html .
SELECT
b.id
, b.from_user
, b.dateadded
, b.posttype
, b.posttext
, b.photoname
, b.blahchoice
, b.commentschoice
, b.mood
, c.defaultphoto
, d.firstn
, d.lastn
, e.status
, f.topostid
, f.commenttext
FROM
t_board b
INNER JOIN
t_userprofiles c ON b.from_user = c.user_id
INNER JOIN
t_users d ON b.from_user = d.id
INNER JOIN
t_friendship e ON e.friend_ids = b.from_user
LEFT JOIN
t_postcomments f ON f.topostid = b.id
WHERE
e.status = 'Friend'
AND e.user_ids = :id
ORDER BY
b.id DESC