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: [Jason] How to alternate banners with each pageload using 1x upload field

By studio-a - April 14, 2011

Hey Jason,

I found this discussion about banner ads and thought I would continue it for our company’s purpose and to expand the topic for anyone that is exploring banner functionality within their website.


This is What We Want to Accomplish:[
-------------------------------------------------------------
Background) We have a client with various product listing pages, each of which has a pagination of 6 to 10 pages.

Goal) To provide 10 different advertising banners (jpegs) per listing page view per pagination click.

Example) Our client has say 70 advertisers for this one particular product listing page. There are a total of 7 paginations clicks (meaning seven different page views for this one product listing category just to be clear). We would like to group ten different RANDOM banners per pagination page. YET, not have a banner advertisement repeat itself throughout the 7 paginations views. Each group of ten banner images will hold a different set of images.

We understand how to pull out the advertisements banners per listing page using Where and Random statements. However, we are not sure how to “group ten random banners” per listing page and “rotate a new group of ten banner images that differ” then the pagination click previously displayed.

We suspect a multidimensional array is required to create the groups of ten then some sort of session variable will be needed to display one group at a time per pagination page view. Then this could loop through and continue per pagination click finally exhausting the full list of advertisers (70 in the case example) and repeat for that listing page.

How difficult is this this type of array to create and combine it with the session variable?

Any light you can shine on this greatly appreciated!

studio-a