This topic is locked
[SOLVED]

 Custom View While Loop

4/27/2012 9:25:00 PM
PHPRunner General questions
S
stiven author

Hello everyone, hopefully someone can help me with this.
I have a custom view where the value are 4 songs separated by a comma, i tried to select each song and display the song as a link to download the lyrics with a while loop the problem here is that the var $value only shows the las iteration of the loop but if i echo the var $value it shows all the iterations and it is actually right here is the code



$arr = explode(",",$value);
$count = count($arr) - 1;
global $conn;
$i = 0;

while($i <= $count){
$sql = "SELECT song_id,song FROM songs WHERE audio = '".$arr[$i]."'";

$res = db_query($sql,$conn);
$row = db_fetch_array($res);
$value = '<a href="download.php?table=songs&amp;field=lyrics&amp;key1='.$row['song_id'].'">'.$row['song'].'</a> ';//this only shows the last song.



echo $value;// this shows all 4 songs with its respectives links to download.

$i++;
}


Thanks

C
cgphp 4/29/2012

Don't echo anything inside a "View as custom" field. Please, check out this version:

$arr = explode(",",$value);
$count = count($arr) - 1;
global $conn;
$songs = "";

$i = 0;

while($i <= $count)

{

$sql = "SELECT song_id,song FROM songs WHERE audio = '".$arr[$i]."'";

$res = db_query($sql,$conn);
$row = db_fetch_array($res);
$songs .= '<a href="download.php?table=songs&amp;field=lyrics&amp;key1='.$row['song_id'].'">'.$row['song'].'</a><br/>';//this only shows the last song.
$i++;

}
$value = $songs;
S
stiven author 4/30/2012

Thanks so much for your help. this worked