I'm working on a project where the user is submitting multiple dates. The dates are then saved in the db along with the current username. What I'm trying to do next, is to get an overview of all submitted dates and the users who have submitted the current date. BUT my problem is, that I only wan't to show ONE date, and then all the users who have selected this unique date. Like this:
- 05.03.2012 = Paul
- 06.03.2012 = Shane, John
- 07.03.2012 = John, Irene
And NOT like this, as it is at the moment:
- 05.03.2012 = Paul
- 06.03.2012 = Shane
- 06.03.2012 = John
- 07.03.2012 = John
- 07.03.2012 = Irene
Are you with me? Because thats the main problem. As for the coding part, I've tried to do like this:
$table_name = $wpdb->prefix . 'my_db';
$my_date_overview = $wpdb->get_results("
SELECT * FROM $table_name
WHERE thedate > NOW()
ORDER by thedate ASC");
foreach ( $my_date_overview as $the_dates ) {
echo $the_dates->thedate;
echo ',';
echo $the_dates->username;
}
Db-table values: ID, thedate, username.
I've tried to use "SELECT DISTINCT thedate", but then I don't get the usernames. Can I even do this filtering process here, or do I need to make a function?
I've tried to google it but without any luck. I'm out of ideas - and knowledge. Can anyone help me out? Thanks