How to alternate banners with each pageload using 1x upload field

4 posts by 3 authors in: Forums > CMS Builder
Last Post: April 14, 2011   (RSS)

Hi, we are attempting to add some advertising space to a client's site we built using CMS Builder.

We want to use 1x Upload field particular to an ad spot on the website that we can use to upload multiple ads that will alternate sequentially with each new page load. Can you explain how to do this?

I hope my request is clear.
Thanks,
Dan

Re: [Dan Maitland] How to alternate banners with each pageload using 1x upload field

By Jason - December 13, 2010

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/

Re: [studio-a] How to alternate banners with each pageload using 1x upload field

By Jason - April 14, 2011

Hi,

So if I understand correctly, you'll have a set of banners sorted into a random order. On each listing page, you want to display 10 of those images. As you go through each page, the 10 images being displayed change, but never repeat. Is that right?

For example, if you have images 1 - 10 on page one and 21 - 30 on page 3, if you go to page 3 and then back to page 1, do you see images 1 - 10 again?

If this is right, I think what you'll need to do is create your entire list of random banners the first time the page loads and then store that in a session array. If you randomize the list each time the page loads, you'll end up repeating images. Then what you'd have to do is display your images starting at your current page number.

For example,
page 1: display images 1 - 10
page 2: display images 11 - 20
page 3: diaplay images 21 - 30
etc.

I'd start out along those lines and see how it goes. Let us know if you run into any problems.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/