<?php
 
include 'dataconfig.php' ;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT m.*
FROM `music` m
INNER JOIN (
    SELECT album, MAX(id) AS max_id
    FROM `music`
    GROUP BY album
) AS grouped_music
ON m.id = grouped_music.max_id
ORDER BY m.id DESC";

$result = $conn->query($sql);

mysqli_query($conn,$sql); 

$response = array();

while($row = mysqli_fetch_array($result)){
    array_push($response,array(
        'id'=>$row['id'],
        'genre'=>$row['genre'],
        'image'=>$row['image']
    ));
}
echo json_encode(array('result'=>$response));
$conn->close();
?>