I'm trying to build a javascript array from a set of retrieved records, using while(). The code looks like this:
echo "showPix = new Array(";
if ($randorder == 0) {
$result = mysql_query("SELECT FROM choushowimages WHERE showid=$showid ORDER BY sortorder", $db);
} elseif ($randorder == 1) {
$result = mysql_query("SELECT , rand() as r FROM choushowimages WHERE showid=$showid ORDER BY r", $db);
}
while ($myrow = mysql_fetch_array($result)) {
$filename = $myrow["filename"];
echo "\"images/slideshows/" . $showid . "/" . $filename . "\",";
}
echo ")\n";
The problem is, I end up with an extra comma, which makes the javascript malfunction. What I want to do is say something like:
while ($myrow = mysql_fetch_array($result)) {
$filename = $myrow["filename"];
if (this is the last record in the $result) {
echo "\"images/slideshows/" . $showid . "/" . $filename . ")"; // no comma and close parenthesis
} else {
echo "\"images/slideshows/" . $showid . "/" . $filename . "\","; // put in the comma
}
Bet this is easy, but it's outside my sphere o' knowledge...