Hi,
I have a slideshow which is displayed with the following piece of code. I need to remove the last comma from the array, as it's breaking in IE. Any suggestions on how to do this? TIA!

<script type="text/javascript">
var mygallery=new fadeSlideShow({
	wrapperid: "headershow", //ID of blank DIV on page to house Slideshow
	dimensions: [570, 145], //width/height of gallery in pixels. Should reflect dimensions of largest image
	imagearray: [

<?php
	$sql = "SELECT * FROM slideshow_images WHERE SlideID = 'header'";
	$result = mysql_query($sql);
	if(mysql_num_rows($result) > 0) {
		while($row = mysql_fetch_object($result))

	{
	echo '["images/slideshows/'.$row->filename.'", "'.$row->link.'", "'.$row->window.'", "'.$row->caption.'"],';
	}
}

 ?>

],
displaymode: {type:'auto', pause:3000, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 1500, //transition duration (milliseconds)
descreveal: "ondemand",
togglerid: ""
})

</script>

    One quick solution would be to append the text in your loop to a string (instead of echoing it at that point), then use [man]rtrim/man with the optional 2nd parameter to remove the comma, then echo the entire string.

      Thanks for the reply 🙂
      I'm not 100% sure what you mean...I tried something like this, but it removes the ", " from each line, not just the last one.

      {
      $string = '["images/slideshows/'.$row->filename.'", "'.$row->link.'", "'.$row->window.'", "'.$row->caption.'"],';
      $trimmed = rtrim($string,",");
      echo $trimmed;
      }
      

        You need to use the ".=" operator to build the string within the loop, then modify it and echo it after the loop:

        <?php
        $text = '';
        $sql = "SELECT * FROM slideshow_images WHERE SlideID = 'header'";
        $result = mysql_query($sql);
        if (mysql_num_rows($result) > 0) {
           while ($row = mysql_fetch_object($result)) {
              $text .= '["images/slideshows/' . $row->filename . '", "' . $row->link . '", "' . $row->window . '", "' . $row->caption . '"],';
           }
        }
        $text = rtrim($text, ',');
        echo $text;
        ?>
        

          Thank you for posting that snippet. I see what you mean now 🙂 It works perfectly now, I appreciate your help

            Write a Reply...