GROUP_CONCAT
should be helpful to you. You can read documentation on it here.
Your query could look like this:
select user_name, group_concat(content,"
") from post group by user_name;
This will group all of the posts together by each user, and then concatenate the content
field of all of a user's rows into a single string separated by newline.
You can see the SQLFiddle with query and results here
(Keep in mind that SQLFiddle prints its results, by default, in tabular HTML. Choose Run SQL -> Plaintext Output
to see the actual newlines printed out)
EDITED (added content below)
If you want to use PHP to handle this, you can do the following:
$query = 'select user_name, group_concat(content,"
") as contents from post group by user_name;'
$result = mysqli_query($query)
print '<table><tr><td>USER NAME</td><td>CONTENTS</td></tr>';
while ($row = mysqli_fetch_assoc($result)) {
print '<tr>';
print '<td>' . $result['user_name'] . '</td>';
print '<td>' . preg_replace("/
/", '<br>' . $result['contents']) . '</td>';
print '</tr>';
}
print '</table>';
Here are links to documentation on some of the functions I used in this example: