João João - 2 years ago 94
SQL Question

Merging MySQL data into the same list

Hi I'm trying to do a change log page.
I have the change log content in a database and then I want to display it by date in a PHP page.

Here's the code:

$getChangeLog = "SELECT * FROM changelog ORDER BY id DESC LIMIT 6";
$query = $conn->query($getChangeLog);
echo "<h1>CHANGE LOG</h1>";
while ($row = mysqli_fetch_assoc($query)) {
echo "<h4>".$row["date"]."</h4>";
echo "<ul><li>".$row["change"]."</li></ul>";

My SQL Databse:

My SQL databse

I want to display unordered lists with changes that have same dates.

It should look like this:

Example Database Done

Answer Source
$getChangeLog = "SELECT * FROM changelog ORDER BY date DESC, id DESC LIMIT 6";      
$query = $conn->query($getChangeLog);
echo "<h1>CHANGE LOG</h1>"; 
$c = 0;
while ($row = mysqli_fetch_assoc($query)) { 
    $list[$c] = $row;
        echo ($c==0?"":"</ul>")."<h4>".$row["date"]."</h4><ul>";  
    echo "<li>".$row["change"]."</li>";
echo "</ul>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download