I need to strip the comma from the last echoed file. So I need to remover the come from the line "$aSong['ID'].'.mp3"},". On the last one that is echoed
while ( $aSong = mysql_fetch_array($sql_get_files) ) {
//Creates an array of $thisSong[ID], $thisSong[Title], etc.
// substr removes the first 4 letters of the KEY
foreach ( $aSong as $sKey => $sValue )
$thisSong[substr($sKey,4)] = stripslashes($sValue);
//Ditch $thisSong for the prev value
$aSong = $thisSong; unset($thisSong);
$mp3r = '';
echo '{name:"'.$aSong['Artist'].' '.$aSong['Title'].
'",mp3:"http://domain.com/uploads/audio/'.$aSong['ID'].'.mp3"},';
}
You could also just populate an array:
You also need to quote your JSON keys so
{mp3:"http...mp3"}becomes{"mp3":"http...mp3"}. If you’re trying to output JSON to the browser for AJAX or whatever, you’ll need something like this instead:Once you have all your output, take it over to JSONlint.com and validate it.