Jump to content


This topic is now archived and is closed to further replies.


php/mysql help me please

Recommended Posts

I'm making discography section for my site using php and mysql.
here is my db structure:
I have 3 tables- albums, tracks and albums_tracks

albums table holds information about albums, album name, release date...ect
tracks table is for song information, song name, lyrics..
albums_tracks is table that connects albums and tracks table.

albums_tracks table

albums_ID - track_ID

but I'm running into a problem with double disc albums. I would like to make something like this:

track list of cd 1
track 1
track 2

track list of cd2.
track 1
track 2

instead of

track listing

what I'm trying to say is that, I want page to return track listing for each CD separately.
maybe someone can help me with this...

thanks a lot
any kind of help will be apprediated.

Share this post

Link to post
Share on other sites
try this:
$a_t_sql = "select  albums_ID , track_ID from albums_tracks";
$a_t_query = mysql_query($a_t_sql);
$a_t_num= mysql_num_rows($a_t_sql);
    $a_t_col = mysql_fetch_array($a_t_query);
    $a_sql = "select * from albums where albums_id = '".$a_t_col[0]."'";
    $t_sql = "select * from track where track_id = '".$a_t_col[1]."'";
    $a_query = mysql_query($a_sql);
    $a_col = mysql_fetch_array($a_query);
    echo $a_col[album_name];
    $t_query = mysql_query($t_sql);
    $t_num= mysql_num_rows($t_sql);
        $t_col = mysql_fetch_array($t_query);
        echo $t_col[track_name];

Share this post

Link to post
Share on other sites
Your structure is fine. Zawadi's code is a little weird. Here's how I would write it:

[code]$albums= mysql_query("select * from albums ORDER BY albums_ID");

while ($album = mysql_fetch_assoc($albums)) {
    echo 'Album: ' . $album['album_name'];

    $tracks = mysql_query("select t.* FROM tracks t INNER JOIN albums_tracks a ON t.track_ID=a.track_ID WHERE a.albums_ID='$album[albums_ID]'");

    while ($track = mysql_fetch_assoc($tracks)) {
        echo '     ' . $track['track_name'];

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.