Howdy folks...
I'm looking to read off sql results and stack them up for display purposes... and having a hell of time getting what I want. I've included some snipped code to explain better what I'm trying to do.
The problem is the array_push in the while loop looks like it's hammering any previous tracks that had already been pushed onto it... resulting in there being just one track in that array, the last one pushed on.
End result I'm looking for should look something like:
artist->( album1->( track1, track2 ... trackn) , album2->( track1 ... trackn) )
What am I missing here?
while ( $line = mysql_fetch_array( $result ) ) {
$records[ $line[ 'artist' ]][ $line[ 'album' ] ] = array();
array_push( $records[ $line[ 'artist' ]][ $line[ 'album' ] ] , $line[ 'title' ] );
}
foreach ( $records as $artist => $albums ) {
$html .= "$artist<br>\n";
foreach ( $albums as $album => $tracks ) {
$html .= " $album<br>\n";
foreach ( $tracks as $key => $value ) {
$html .= " $value<br>\n";
}
}
}