Re: [Dan Maitland] How to alternate banners with each pageload using 1x upload field
Hi,
If you want to cycle through them one at a time, you can do this using s $_SESSION variable.
In this example, we'll assume the name of your record variable is called $advertisement and the name of your upload field is 'ads':
<?php
if(!array_key_exists('imageIndex',@$_SESSION)||($_SESSION['imageIndex']==count($advertisement['ads'])-1)){
//set the sesssion variable to 0 if it does not exist or it hits the maximum number of images
$_SESSION['imageIndex']=0;
}
else{
//increment the session variable
$_SESSION['imageIndex']+=1;
}
$image = $advertisement['ads'][$_SESSION['imageIndex']];
?>
The variable $image now hold a single image record from your upload field. You can use this variable to output your image anywhere you like. Once you've cycled through all the uploaded images, it will start back at the beginning.
Give this a try and let me know if you run into any problems.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/