Do not print comma after last image - what markup?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 15, 2010 (RSS)
By zaba - December 15, 2010
Hi To explain more fully, I am using fancybox jquery plugin and using php to generate the javascript which pulls the images into fancybox on click of a link. The problem is that in the javascript where it lists the images from the database I do not want a comma after the last one as it shows there to be another image (only in internet explorer of course).
I'll paste the code which works fine, the only issue is the extra comma at the end on the line obviously it places this comma after each image instance, but i dont want it after the last.
see full code
I'll paste the code which works fine, the only issue is the extra comma at the end on the line obviously it places this comma after each image instance, but i dont want it after the last.
<?php $gallery_va.="',"; ?>
<?php endif ?>
see full code
<?php
$gallery_va='
<script type="text/javascript">
$(document).ready(function() {
$("#gallery_va").click(function() {
$.fancybox([';
?>
<?php foreach ($gallery_villa_ambasadaRecord['images'] as $upload): ?>
<?php if ($upload['isImage']): ?>
<?php $gallery_va.="'"; ?>
<?php $gallery_va.=$upload['urlPath']; ?>
<?php $gallery_va.="',"; ?>
<?php endif ?>
<?php endforeach ?>
<?php $gallery_va.="
], {
'titlePosition' : 'over',
'titleShow' : true,
'autoDimensions' : 'true',
'autoScale' : true,
'transitionIn' : 'elastic',
'transitionOut' : 'none',
'type' : 'image',
'overlayOpacity' : '0.8',
'overlayColor' :'#000',
'showNavArrows' : true,
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id=\"fancybox-title-over\">Zdjęcie ' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
}
});
});
});
</script> ";
echo $gallery_va;
?>
Re: [zaba] Do not print comma after last image - what markup?
By Jason - December 15, 2010
Hi,
You can use rtrim to remove the last comma at the right of the string:
Hope this helps
You can use rtrim to remove the last comma at the right of the string:
<?php foreach ($gallery_villa_ambasadaRecord['images'] as $upload): ?>
<?php if ($upload['isImage']): ?>
<?php $gallery_va.="'"; ?>
<?php $gallery_va.=$upload['urlPath']; ?>
<?php $gallery_va.="',"; ?>
<?php endif ?>
<?php endforeach ?>
<?php $gallery_va=rtrim($gallery_va,',');?>
<?php $gallery_va.="
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Do not print comma after last image - what markup?
By zaba - December 15, 2010
Perfect!
thanks a million!
thanks a million!