Jump to content

Banner help


Sean_J

Recommended Posts

Hello everyone

 

Im looking for some help on rotating banners, I've searched the internet and found nothing.

 

Basically on my homepage I want to have six banners positioned down the right hand side of the page. (All visable at the same time)

 

for e.g

 

Banner1.jpg

Banner2.jpg

Banner3.jpg

Banner4.jpg

Banner5.jpg

Banner6.jpg

 

Once the page has been refreshed I would like the banners to change position, for e.g

 

Banner2.jpg

Banner3.jpg

Banner4.jpg

Banner5.jpg

Banner6.jpg

Banner1.jpg

 

Bassicly each banner will have its turn of being at the top of the page.

 

Can anyone please tell me how I go about doing this, or if there is a certain script I could use.

 

Regards

 

Sean

Link to comment
Share on other sites

here you go it took a long time to cook up

 

 

<script>
var arrBanner = new Array();

function random(arrAvoid,intMax)
{
var intRand = Math.ceil(Math.random()*intMax);
if (!inArray(arrAvoid,intRand))
{
	arrBanner.push(intRand);
}
else 
{
	random(arrAvoid,intMax);
}
}

function inArray(arrArray,strSearch)
{
for (strKey in arrArray)
{
		if (arrArray[strKey]==strSearch)
		{
		    return true;
		}
}
return false
}	

for (i=0;i<6;i++)
{
random(arrBanner,6);
}

for (strKey in arrBanner)
{
document.write("<img src='Banner"+arrBanner[strKey]+".jpg'><BR>");
}


</script>

Link to comment
Share on other sites

here you go

 

<script>
var arrBanner = new Array();
var arrLinks = new Array();

arrLinks[1] = "Link 1";
arrLinks[2] = "Link 2";
arrLinks[3] = "Link 3";
arrLinks[4] = "Link 4";
arrLinks[5] = "Link 5";
arrLinks[6] = "Link 6";


function random(arrAvoid,intMax)
{
var intRand = Math.ceil(Math.random()*intMax);
if (!inArray(arrAvoid,intRand))
{
	arrBanner.push(intRand);
}
else 
{
	random(arrAvoid,intMax);
}
}

function inArray(arrArray,strSearch)
{
for (strKey in arrArray)
{
		if (arrArray[strKey]==strSearch)
		{
		    return true;
		}
}
return false
}	

for (i=0;i<6;i++)
{
random(arrBanner,6);
}

for (strKey in arrBanner)
{
document.write("<a href=\""+arrLinks[arrBanner[strKey]]+"\"><img src='Banner"+arrBanner[strKey]+".jpg' border=0><BR>");
}


</script>

 

where its Link 1 put the link for banner1.jpg and so on... hope its helpful.. I see your new to the forum.. Welcome to PhpFreaks :)

Link to comment
Share on other sites

No not at all, I love to help out fellow programmers, here you go new and improved :)

 

<script>
var arrBanner = new Array();
var arrLinks = new Array();
var arrBannerFiles = new Array();

arrBannerFiles[1] = "Banner1.jpg";
arrBannerFiles[2] = "Banner2.jpg";
arrBannerFiles[3] = "Banner3.jpg";
arrBannerFiles[4] = "Banner4.jpg";
arrBannerFiles[5] = "Banner5.jpg";
arrBannerFiles[6] = "Banner6.jpg";


arrLinks[1] = "Link 1";
arrLinks[2] = "Link 2";
arrLinks[3] = "Link 3";
arrLinks[4] = "Link 4";
arrLinks[5] = "Link 5";
arrLinks[6] = "Link 6";


function random(arrAvoid,intMax)
{
var intRand = Math.ceil(Math.random()*intMax);
if (!inArray(arrAvoid,intRand))
{
	arrBanner.push(intRand);
}
else 
{
	random(arrAvoid,intMax);
}
}

function inArray(arrArray,strSearch)
{
for (strKey in arrArray)
{
		if (arrArray[strKey]==strSearch)
		{
		    return true;
		}
}
return false
}	

for (i=0;i<6;i++)
{
random(arrBanner,6);
}

for (strKey in arrBanner)
{
document.write("<a href=\""+arrLinks[arrBanner[strKey]]+"\"><img src='"+arrBannerFiles[arrBanner[strKey]]+"' border=0><BR>");
}


</script>

 

now your filename can be anything... just keep the consistency, also I added intNumberOfBanners for the number of banner incase you want to remove or add another one just keep the number consistent with links and filenames

 

hope its helpful

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.