I have this mysql Table:
+--------------------+---------+-------+
| date | query | count |
|--------------------+---------+-------|
|2012-11-18 09:52:00 | Michael | 1 |
|2012-11-18 10:47:10 | Tom | 2 |
|2012-11-17 15:02:12 | John | 1 |
|2012-11-17 22:52:10 | Erik | 3 |
|2012-11-16 09:42:01 | Larry | 1 |
|2012-11-16 07:41:33 | Kate | 1 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and so on. I can simply take results and order them by date in one row via this code:
$queries = mysql_query("SELECT * FROM my_tables ORDER BY date DESC LIMIT 20");
while($row = mysql_fetch_array($queries)){
echo "Name ".$row['query']."";
}
But how to display elements from table ordered by specific date like this:
In 2012-11-18:
Michael
Tom
In 2012-11-17:
John
Erik
In 2012-11-16:
Larry
Kate
and so on. Thanks!
Use this:
+1 good question, THIS QUESTION IS NOT SIMPLY HOW TO ORDER A QUERY!!
I think this can be done using
GROUP_CONCAT
function. this will combine the matching results when you group them and seperate them by commas. ONce you have the results you can explode or do whatever you wanthttp://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-group_concat.php
Your going to have to convert and group by date, and group_concat the names. then (in php or whathaveyou) explode the names by commas, and echo the date followed by the names for each result.
edit Looks like you wanted a PHP way to solve this? oops
Try the WHERE statement:
Here is teh PHP code:
Output:
Note that while this code "groups" rows by one column, it can easily be extended to group rows by multiple columns. Left as an exercise.
What about