How can I run one mysql query to output data both 'ungrouped' and also 'grouped by' user name?
I have a query fetching all the data associated with a user's posts. in the while loop I am retrieving the user's name and inputing it into a select/option dropdown. Below that it is actually outputting the individual posts - User Name and Post.
This all working fine with the exception that, if a user has more than one post his/her name is duplicated in the dropdown. And if I use the clause GROUP BY in the query, then it will not display all the posts - just one per user.
I can't run a separate query (or at least i couldn't find a solution) since i have the query setup for pagination, so running a separate query on the dropdown would just display ALL the users, and I just want to display the ones currently displayed on the page.
Is there a way to output data both 'ungrouped' and also 'grouped by' inside the same query?
Here is an example of my desired output. NOTE: The user Michael Smith has 2 posts, but his name only appears in the dropdown once.
<h3>Posts Filter</h3>
<select>
<option>Michael Smith</option>
<option>James Hendrickson</option>
<option>Lucy Michaels</option>
</select>
<br>
<br>
<hr>
<div style="width:45%;height:200px;float:left;border:1px solid #ddd;padding:10px;margin:2.5%;box-sizing:border-box;">
<h2>Michael Smith</h2>
<p>Bacon ipsum dolor amet short ribs kevin ribeye meatball filet mignon swine pork loin spare ribs, pork belly cow tenderloin venison...</p>
</div>
<div style="width:45%;height:200px;float:left;border:1px solid #ddd;padding:10px;margin:2.5%;box-sizing:border-box;">
<h2>James Hendrickson</h2>
<p>Bacon ipsum dolor amet short ribs kevin ribeye meatball filet mignon swine pork loin spare ribs, pork belly cow tenderloin venison...</p>
</div>
<div style="width:45%;height:200px;float:left;border:1px solid #ddd;padding:10px;margin:2.5%;box-sizing:border-box;">
<h2>Michael Smith</h2>
<p>Bacon ipsum dolor amet short ribs kevin ribeye meatball filet mignon swine pork loin spare ribs, pork belly cow tenderloin venison...</p>
</div>
<div style="width:45%;height:200px;float:left;border:1px solid #ddd;padding:10px;margin:2.5%;box-sizing:border-box;">
<h2>Lucy Michaels</h2>
<p>Bacon ipsum dolor amet short ribs kevin ribeye meatball filet mignon swine pork loin spare ribs, pork belly cow tenderloin venison...</p>
</div>
<hr>
<br>
<span style="margin: 0 10px 0 0;width:30px;height;30px;line-height:30px;text-align:center;display:block;float:left;color:#ddd;background:#000;">1</span>
<span style="margin: 0 10px 0 0;width:30px;height;30px;line-height:30px;text-align:center;display:block;float:left;color:#000;background:#ddd;">2</span>
<span style="margin: 0 10px 0 0;width:30px;height;30px;line-height:30px;text-align:center;display:block;float:left;color:#000;background:#ddd;">3</span>
<span style="margin: 0 10px 0 0;width:30px;height;30px;line-height:30px;text-align:center;display:block;float:left;color:#000;background:#ddd;">4</span>
<span style="margin: 0 10px 0 0;width:30px;height;30px;line-height:30px;text-align:center;display:block;float:left;color:#000;background:#ddd;">5</span>
<br>
<br>
Thank you in advance.
Serge