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)

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

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/