"display mysql results by date" Answer’s

0

Here is teh PHP code:

$query = mysql_query("SELECT date, query FROM table6 ORDER BY date DESC LIMIT 20");
$group_date = null;
while ($row = mysql_fetch_assoc($query)) {
    if ($group_date !== substr($row["date"], 0, 10)) {
        $group_date = substr($row["date"], 0, 10);
        echo "<h1>$group_date</h1>n";
    }
    echo "${row['query']}<br>n";
}

Output:

2012-11-18

Tom

Michael

2012-11-17

Erik

John

2012-11-16

Larry

Kate

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.

Wednesday, March 31, 2021
 
qitch
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share