I'm trying to make a multi-user page where user posts something, and posts are grouped and sorted by the user id and display only several of them on main page.
I have a table where it stores user information (id, password etc) and another table that stores the posts (content, post id, poster id).
What I'm stuck at and wondering is that I know I should use GROUP BY or DISTINCT to do it, but when I use it, it would only display only one post on each user. and it will output them all in one row.
$result = mysqli_query($con, "SELECT * FROM post GROUP BY author_id") or die(mysqli_error($con));
while($row = mysqli_fetch_array($result)){
$title = $row['title'];
$id = $row['post_id'];
$author = $row['author_id'];
echo "\n<div class=\"thumb\">";
echo "<p>$author</p>";
echo "<div class=\"thumb-title\">$title</div>";
echo "\n</div>";
}
Output
User1 User2
Post1 post2
I want this to be like
User1
Post1 Post2 Post3 (see more)
User2
Post1 Post2 Post3 (see more)
...