|
-
May 11th, 2014, 06:25 PM
#1
Thread Starter
Fanatic Member
Is there a better way for this code? also is there a way to remove duplicates?
PHP Code:
<?php
$genre1 = mysql_query ( "SELECT * FROM `Genres` WHERE `ID` = '$sta->Genre1'" );
$gen1 = mysql_fetch_object ( $genre1 );
$genre2 = mysql_query ( "SELECT * FROM `Genres` WHERE `ID` = '$sta->Genre2'" );
$gen2 = mysql_fetch_object ( $genre2 );
$genre3 = mysql_query ( "SELECT * FROM `Genres` WHERE `ID` = '$sta->Genre3'" );
$gen3 = mysql_fetch_object ( $genre3 );
$lfm = "http://ws.audioscrobbler.com/2.0/?method=tag.getweeklyartistchart&tag=$gen1->Genre&api_key=05f100c7d5bea70cd7f3a82e29b989a1&format=json&format=json&lang=en&limit=6";
$ch=curl_init($lfm);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);
$json = json_decode($r, true);
if(!isset($json['weeklyartistchart']['artist'][1]['name'])){ echo "No Result";}else {
foreach ($json['weeklyartistchart']['artist'] as $track) {
$artist = $track['name'];
$image = $track['image'][3]['#text'];
$url = preg_replace("/ /s","_" , $artist);
?>
<td>
<li class="crop"> <a href ="artist.php?artist=<?echo $url;?>"> <img src ="http://weloveradio.co.uk/timthumb.php?src=<? echo $image;?>&w=100%&h=100&z=1&q=100" width = "100"> </a> </li>
</td>
<?}}?>
</tr>
<tr>
<?
$lfm = "http://ws.audioscrobbler.com/2.0/?method=tag.getweeklyartistchart&tag=$gen2->Genre&api_key=05f100c7d5bea70cd7f3a82e29b989a1&format=json&format=json&lang=en&limit=6";
$ch=curl_init($lfm);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);
$json = json_decode($r, true);
if(!isset($json['weeklyartistchart']['artist'][1]['name'])){ echo "No Result";}else {
foreach ($json['weeklyartistchart']['artist'] as $track) {
$artist = $track['name'];
$image = $track['image'][3]['#text'];
$url = preg_replace("/ /s","_" , $artist);
?>
<td>
<li class="crop"> <a href ="artist.php?artist=<?echo $url;?>"> <img src ="http://weloveradio.co.uk/timthumb.php?src=<? echo $image;?>&w=100%&h=100&z=1&q=100" width = "100"> </a> </li>
</td>
<?}}?>
</tr>
</tr>
<tr>
<?
$lfm = "http://ws.audioscrobbler.com/2.0/?method=tag.getweeklyartistchart&tag=$gen3->Genre&api_key=05f100c7d5bea70cd7f3a82e29b989a1&format=json&format=json&lang=en&limit=6";
$ch=curl_init($lfm);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);
$json = json_decode($r, true);
if(!isset($json['weeklyartistchart']['artist'][1]['name'])){ echo "No Result";}else {
foreach ($json['weeklyartistchart']['artist'] as $track) {
$artist = $track['name'];
$image = $track['image'][3]['#text'];
$url = preg_replace("/ /s","_" , $artist);
?>
The code above is from my website, it pulls info from the last fm api. Sometimes it displays duplicates,
for example row 1 pulls info from Genre1, lets say that shows the artist UB40
row2 pulls from a different tag / genre, but will also display UB40 if that has the same tag on last fm.
Hope this makes sense.
Jamie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|