BadGoat Posted September 12, 2007 Share Posted September 12, 2007 Hello! Looking for a kick in the right direction... How would I go about nesting an if/else within an if/else? As an example, let's say I have a list of music groups, and by clicking one of them, a list of their albums is displayed. (this part I can do!) But I want a list of the songs associated with that album to be displayed below the album. Perhaps nesting an if/else within an if/else is not the answer? I have tinkered with some theoretical code, and the only time I have been able to return anything, it's a single wrong song in every other album list. Any help would be most appreciated. Here's a bit of code which I've successfully used to $sqlquery = "SELECT song.*, album.*group.* FROM song, album, group WHERE song.song_id = album.song_id AND album.group_id = group.group_id AND group.group_id = '$group_id' "; $queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !"); $row = mysql_fetch_row($queryresult); $album= $row[0]; $tdcount = 1; $numtd = 1; // number of cells per row echo ' '; mysql_data_seek($queryresult,0) ; while($row = mysql_fetch_array($queryresult)) { if ($tdcount == 1) echo ''.$row['album'],' '; if ($tdcount == $numtd) { echo "<br />"; $tdcount = 1; } else { $tdcount++; } } Link to comment https://forums.phpfreaks.com/topic/69075-nesting-an-inelse-within-an-ifelse-is-it-my-answer/ Share on other sites More sharing options...
Barand Posted September 12, 2007 Share Posted September 12, 2007 So guess you have structure like [pre] group album song ---------- ----------- ----------- group_id --+ album_id --+ song_id group | album | song +--< group_id +---< album_id [/pre] <?php $sql = "SELECT a.album, s.song FROM song s INNER JOIN album a ON s.album_id = a.album_id INNER JOIN group g ON a.group_id = g.group_id WHERE group_id = '$group_id' ORDER BY album, song"; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $lastAlbum = ''; while (list($album, $song) = mysql_fetch_row($res)) { if ($lastAlbum != $album) { echo "<h3>$album</h3>"; $lastAlbum = $album; } echo "$song <br />"; } Link to comment https://forums.phpfreaks.com/topic/69075-nesting-an-inelse-within-an-ifelse-is-it-my-answer/#findComment-347387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.