Rate this script:  I Love it  /   I Hate it

PHP last.fm chart creator


Code


<?php
/**********************************************************************************************
www.strydominc.za.net
Created by Jurgen Strydom, 19-08-2006, jurgen.strydom@gmail.com
Read the readme.txt
Version 1.01, 05-09-2006
**********************************************************************************************/

?>
<link href="lastfmbar.css" rel="stylesheet" type="text/css">
<div>
<?php
//User settings -> needs your attention
$user = "Alkine"; //Your username
$width = 700; //width of the list

//Code you should not worry about
$file = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml";
$xml = simplexml_load_file("$file");
$big = $xml->artist[0]->playcount;
$total = count($xml->artist);
$factor$width /$big;
?>
<table width="<?php echo $width ?>" border="0" cellpadding="0" cellspacing="0"
 <?php
 for ($k=0 ; $k<=$total - 1; $k++) {
        $barlen = round(($xml->artist[$k]->playcount * $factor), 0);
 ?>
  <tr>
    <td width="<?php echo $width ?>" height="10" valign="center"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="<?php echo $barlen ?>" height="10" valign="center" class="lastfmbar"><?php
                if ($barlen >= (($width + 100) /2)) {
                        echo "<div align=\"right\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
                }
                if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
                        echo "<div align=\"right\">", $xml->artist[$k]->playcount ," -</div>";
                }
                if ($barlen < ($width / 3)) {
                        echo "&nbsp;";
                }              
                ?></td>
        <td width="<?php echo $width - $barlen ?>" valign="center"><?php
                if ($barlen >= (($width + 100) /2)) {
                        echo "&nbsp;";
                }
                if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
                        echo "<div align=\"left\"><b>&nbsp;", $xml->artist[$k]->name ,"</b></div>";
                }
                if ($barlen < ($width / 3)) {
                        echo "<div align=\"left\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
                }              
                ?></td>
      </tr>
    </table></td>
  </tr>
  <?php
  }
  ?>
</table>
</div>
<?php
/**********************************************************************************************
Changelog:

Version 1.01
Fixed a bug that caused the bar sizes to display incorrectly.

Version 1
First release.
**********************************************************************************************/

?>
 

 

 
PHP last.fm chart creator scripts | PHP last.fm chart creator snippet | PHP last.fm chart creator example | PHP last.fm chart creator tutorial | PHP last.fm chart creator code