The first part of this code (lines 1-19) are fetching album names from a list of tracks from a mysql database. The classes and functions shown are of the joomla CMS. This is all working fine and I can get the list of albums displayed. $artist is a variable in the URL. What I am then trying to do (line 20 to close tag #1) is to find the songs that correlate to that specific album and artist. Using the example of the database finding two albums or more albums is where we run into the problem. I can get the song lists for both and that is all successful. The thing is that (i dont know if this makes sense) but the arrays aren't differentiating between the different albums. So when I list the songs and albums on a later page (second php tag set) I get the same song listing for both albums.
That is the problem. The DEBUG I have set up shows me that I am getting the song and album data correctly from the db, it just shows that both of the arrays are identified by the number zero and are then being lumped together. The album that is fetched second is the one whose songs are shown for both albums.
<?php
if(isset($artist)) {
$query = 'SELECT DISTINCT album, picture FROM `songlist` WHERE artist = "'.rawurldecode($artist).'" ORDER BY album ASC';
$database->setQuery($query);
$album_name = $database->LoadResultArray(0);
$album_picture = $database->LoadResultArray(1);
print_r($album_name);
$this->assignRef( 'album_name', $album_name );
$this->assignRef( 'album_picture', $album_picture );
//Cycle through albums and get songlist
//Find number of albums
$query = 'SELECT COUNT(DISTINCT album) as num FROM `songlist` WHERE artist = "'.rawurldecode($artist).'" ORDER BY album ASC';
$database->setQuery($query);
$numalbums = $database->LoadObject();
for ($x = 0, $n = $numalbums->num; $x < $n; $x++)
{
$query = 'SELECT title, ID FROM songlist WHERE artist = "'.rawurldecode($artist).'" AND album = "'.$this->album_name[$x].'" ORDER BY title ASC';
$database->setQuery($query);
$songs = $database->LoadResultArray(0);
$songIDs = $database->LoadResultArray(1);
//DEBUG
print_r($songs);
echo '<br /><br />';
$this->assignRef( 'songs', $songs );
$this->assignRef( 'songIDs', $songIDs );
}
}
?>
<?php
$h = 0;
for ($j=0, $y=count( $this->album_name ); $j < $y; $j++)
{
$row =& $this->album_name[$j];
$row2 =& $this->album_picture[$j];
$script = 'window.addEvent(\'domready\', function(){ ';
$script .= 'var mySlide'.$j.' = new Fx.Slide(\'slide'.$j.'\'); ';
$script .= 'mySlide'.$j.'.hide(); ';
$script .= ' $(\'toggle'.$j.'\').addEvent(\'mousedown\', function(e){ e = new Event(e); mySlide'.$j.'.toggle(); e.stop(); }); }); ';
$document->addScriptDeclaration( $script );
//Find tracklist for album
echo '
<tr>
<td width="9%" valign="center">'; if(file_exists('components/com_radio/albumcovers/'.$dj.'/'.$row2)) { echo '<img src="components/com_radio/includes/phpThumb/phpThumb.php?src=../../albumcovers/'.$dj.'/'.$row2.'&w=35" />'; } else { echo '<img width="35px" height="35px">'; } echo '</td><td width="85%" valign="middle"> '.$row.'</td><td width="1%"></td><td width="5%" valign="middle"><a id="toggle'.$j.'" name="toggle'.$j.'" class="slideTitleLink"><span class="slideTitle">[+/-]</span></a>
<tr><td colspan="3">
<div id="slide'.$j.'" class="slideBox" style="margin-left:50px;">
<table border="0">
';
for ($r=0, $q=count( $this->songs ); $r < $q; $r++)
{
echo '<tr><td width="100%"><a href="index.php?option=com_radio&view=songinfo&dj='.$dj.'&songID='.$this->songIDs[$r].'">'.$this->songs[$r].'</a></td><!--<td width="1%"></td><td width="3%">»</td>--></tr>';
}
echo ' </table> </div>
</td></tr>
</td>
</tr>';
}
?>
<?php } ?>
This is what I get from the DEBUG part of my script:
I think that the fact that both arrays are Array [0] is the problem. Would that make sense?
Can anyone identify what the problem is and how I might be able to fix it?
Thank you very much.
Hess Smith