I'm starting to learn some PHP/Mysql and I'm strugle how can I make this works.
I have 2 tables. One called ALBUM and the other TRACKS On the ALBUM I have all the album info that I need (title, release date, cover) and on the TRACKS I have all the tracks name and the album id related.
I could make the SELECT works fine and grab all the content, but how can I filter by ALBUM name for example and display all tracks related for that album?
Right now I have this
define("MYSQLUSER", "root");
define("MYSQLPASS", "root");
define("HOSTNAME", "localhost");
define("MYSQLDB", "music");
$connection = new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
die('Could not connect: ' . $connection->connect_error);
}else{
$query = "SELECT * from album AS a JOIN tracks AS t ON t.album = a.id ORDER BY a.id, t.trackNumber, t.album";
$result_obj = '';
$result_obj = $connection->query($query);
while($result = $result_obj->fetch_array(MYSQLI_ASSOC)){
$items[] = $result;
}
foreach ($items as $item){
echo "<ul><li>";
echo $item['name'];
echo " - "
echo $item['file'];
echo "</li></ul>";
}
Problem is that will output all album/tracks separate from each other.
Like this:
<ul>
<li>Album 1 - file 1</li>
</ul>
<ul>
<li>Album 1 - file 2</li>
</ul>
<ul>
<li>Album 2 - file 1</li>
</ul>
How can I make the albums on the same ul/li tags? I knwo is my foreach loop. But what I can do?
So will be like this:
<ul>
<li>Album 1 - file 1, Album 1 - file 2, Album 1 - file3</li>
<li>Album 2 - file 1</li>
</ul>
Thanks