Jump to content

Problem with links in a loop


wee493

Recommended Posts

I'm creating a stat-type page for last.fm. Using a foreach loop I'm returning the data from the last.fm api. I'm linking artist names to the appropriate artist page and so on with songs & albums. The only problem is that in two of the three loops only the links from the first result are working. The <a hef is displayed when viewing the html source, I'm stumped. You can see for yourself here... http://wee493.com/lastfm/?user=josho493 (Feel free to plugin your own last.fm username here if you would like :P)

 

Here's one of the loops that is having the problem.

<?PHP
$top_tracks = $lastfm->user_getTopTracks("user=".$user);

foreach ($top_tracks['lfm']['toptracks']['track'] as $trk){
$rank = $trk['attr']['rank'];
$name = $trk['name']['value'];
$playcount = $trk['playcount']['value'];
$url = $trk['url']['value'];
$artist = $trk['artist']['name']['value'];
$artist_link = $trk['artist']['url']['value'];

if($rank <= '10'){
?>


<div class="top">
    	<div class="rank">
        	<?PHP echo $rank; ?>
        </div>
        <div class="top-song-info">
        	<div class="title">
            	<a href="<?PHP echo $url; ?>" target="_blank"><?PHP echo $name; ?></a>
            </div>
            
            <div class="artist-info">
            	<span class="artist"><a href="<?PHP echo $artist_link; ?>" target="_blank"><?PHP echo $artist; ?></a></span>
                <span class="date"><?PHP echo $playcount; ?> Plays</span>
            </div>
            
            
        </div>
    </div>


<?PHP
} /* end if */ } // end foreach

 

Any help is appreciated! Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/204466-problem-with-links-in-a-loop/
Share on other sites

Archived

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

×
×
  • Create New...

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.