halo-eleven Posted March 7, 2006 Share Posted March 7, 2006 HelloI'm making discography section for my site using php and mysql.here is my db structure:I have 3 tables- albums, tracks and albums_tracksalbums table holds information about albums, album name, release date...ecttracks table is for song information, song name, lyrics..albums_tracks is table that connects albums and tracks table.EX:albums_tracks tablealbums_ID - track_ID1-132-145-12ect...but I'm running into a problem with double disc albums. I would like to make something like this:track list of cd 1track 1 track 2track list of cd2.track 1track 2instead of track listingtrack1track2track1track2what 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 lotany kind of help will be apprediated. Link to comment https://forums.phpfreaks.com/topic/4324-phpmysql-help-me-please/ Share on other sites More sharing options...
zawadi Posted March 7, 2006 Share Posted March 7, 2006 try this:[code] $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);for($n=0;$n<$a_t_num;$n++){ $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); for($nt=0;$nt<$t_num;$nt++;){ $t_col = mysql_fetch_array($t_query); echo $t_col[track_name]; }}[/code] Link to comment https://forums.phpfreaks.com/topic/4324-phpmysql-help-me-please/#findComment-15031 Share on other sites More sharing options...
halo-eleven Posted March 7, 2006 Author Share Posted March 7, 2006 Thanks, but i think at first i need to change my database structure or add some tables... :( Link to comment https://forums.phpfreaks.com/topic/4324-phpmysql-help-me-please/#findComment-15050 Share on other sites More sharing options...
wickning1 Posted March 7, 2006 Share Posted March 7, 2006 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']; }}[/code] Link to comment https://forums.phpfreaks.com/topic/4324-phpmysql-help-me-please/#findComment-15064 Share on other sites More sharing options...
txmedic03 Posted March 7, 2006 Share Posted March 7, 2006 Remove my reply, please. Link to comment https://forums.phpfreaks.com/topic/4324-phpmysql-help-me-please/#findComment-15096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.