Gossamer Forum
Home : Products : DBMan : Customization :

random banner images

Quote Reply
random banner images
I will need to add clickable, random rotating banner images on one of my DBMan driven web sites. The banners will need to be displayed on the html.pl page.
Can anyone help me in this.
I have tried a client-side javascript but it fails after loading just the first image.

Regards,
Chef Mars
Quote Reply
Re: [chefmars] random banner images In reply to
To give you a general idea of how to get a random banner, all of which click to the same URL:

Put all your banners into one directory.
Read the directory, assigning the names of the files to an array.
Generate a random integer
Display the banner, using the array and the random integer -- something like $bannerfile[$random]

If each banner has its own URL, you'll need to define your banners and URLs. Something like:

$banner[0] = "prettybanner.jpg";
$urlclick[0] = "http://www.someplacenice.com";
$banner[1] = "anotherbanner.jpg";
$urlclick[1] = "http://www.anotherplace.com";

and so on

Generate your random number and then use it to print out your banner and URL.

I'm not sure what you mean by "random rotating" banners. You can have random banners or you can have rotating banners. I don't know how you can have both.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] random banner images In reply to
JPD,

Once again thanks for the quick response.
This time however I think I am going to be out of my knowledge depth so any detailed help you can give will be appreciated

Beyond getting the images in a readable directory I do not know where to begin on this.

I hate to give up before starting but know when I am not going to succeed.

Regards,
Chef Mars

Quote Reply
Re: [mars2] random banner images In reply to
I can help you with it, but I need to know which of the scenarios you are dealing with. Is there just one URL with the multiple banners or does each banner have a different URL?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [mars2] random banner images In reply to
Here's a good tutorial (it seems really simple) on banner rotating... although this site hasn't been updated in a couple of years I think the info and scripts are still pretty good.

http://www.bignosebird.com/recycle.shtml

He gives examples of two different kinds.
Quote Reply
Re: [JPDeni] random banner images In reply to
Thanks very much, JPD
Each banner will have its own different URL.

Regards,
Chef Mars
Quote Reply
Re: [Watts] random banner images In reply to
Watts,

Thank you very much for helping.

I will take alook at the tutorial but want to avoid shtml and server includes if possible.

Regards,
Chef Mars
Quote Reply
Re: [mars2] random banner images In reply to
In your .cfg file, define your banner files and their associated URLs into arrays. Be sure to use the whole URL, including the http:// part.

$banner[0] = "prettybanner.jpg";
$urlclick[0] = "http://www.someplacenice.com";
$banner[1] = "anotherbanner.jpg";
$urlclick[1] = "http://www.anotherplace.com";
and so on

Notice that each banner and its URL have the same place in their own array. Be sure to use [0] for the first element of your array.

In html.pl, wherever you want your banner to print out, add the following:

$index = rand @banner;
print qq|<a href="$urlclick[$index]"><img src="http://path.to.graphics.directory/$banner[$index]"></a>|;

If your banners are all the same size, it would be good form to include height and width attributes to your img src tag.

I've never done this, but this seems like the logical way to do it. You can have weighted randomness,too. If you wanted one banner to show up twice as often as the rest, just define that graphic and URL twice.

If you want them to rotate, then you have a completely different ball game.

(edited to fix the error in the link.)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Dec 30, 2005, 6:55 AM
Quote Reply
Re: [JPDeni] random banner images In reply to
JPD,
That code seems in keeping with your genuis-simple and efficient.
The problem is that it is not pulling the images. Got any ideas?

Regards,

Chef Mars
================================================
In the cfg file I have the following::
$banner[0] = "banner1.gif";
$urlclick[0] = "http://www.antenen.com";
$banner[1] = "banner2.gif";
$urlclick[1] = "http://www.google.com";

In html.pl the following::
$index = rand @banner;
print qq|<a href="$urlclick[$index]"><img src=""></a"]http://www.marscafe.com/bimages/$banner[$index]"></a>|;

It is posted at::
http://www.marscafe.com/...=*&nh=1&mh=1
Quote Reply
Re: [chefmars] random banner images In reply to
The code for the images is wrong. I know I typed it right. It's likely that the forum software is changing it. Let's try it again.

Code:
print qq|<a href="$urlclick[$index]"><img src="http://www.marscafe.com/bimages/$banner[$index]"></a>|;


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] random banner images In reply to
JPD,

With that minor code repair the banners are displaying just as they should. Thank you for your interest in my challenge/problem and also for providing a teaching-learning situation regarding the introduction of a new array into DBMan.

As always, with thanks and respect-
Chef Mars
Quote Reply
Re: [chefmars] random banner images In reply to
I use a banner application (web based) provided by http://www.focalmedia.net/htmlrotate_docs.html , it is quite simple to set up. all you need to do it to include the js script line in your html.pl header and add another line of code into the body of your page. advantage is that you dont have to keep on fiddling with your html.pl file all the time. you can add, delete, previe the ban nerfrom the application url setup on you server. I say this becuase i used to use a similar .js script to those advicesd in other replies 9i am not saying it won't work) but if you have many banners in one random rotation or many other banners on the page then it can be painfull. hope it helps.