Jump to content


Photo

Banner stored as PHP


  • Please log in to reply
3 replies to this topic

#1 ptex

ptex
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 22 May 2006 - 03:38 PM

How can I make this

<h1 id="siteName" align="center"><script language="JavaScript">
<!--
image = new Array
image[1]="images/TopBanner1.jpg"
image[2]="images/TopBanner2.jpg"
image[3]="images/TopBanner3.jpg"
image[4]="images/TopBanner4.jpg"
image[5]="images/TopBanner5.jpg"
image[6]="images/TopBanner6.jpg"
image[7]="images/TopBanner7.jpg"
image[8]="images/TopBanner8.jpg"
image[9]="images/TopBanner9.jpg"
image[10]="images/FlowersBanner.jpg"
// Create a random number between 1 and ten
random_num = (Math.round((Math.random()*9)+1))

document.write("<img src=\"" + image[random_num] + "\">");

//-->
</script></h1>

Look more like this
<?echo $banner?>

I would like to have the ability to change the banner images with out going to every page or renaming then every time?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 May 2006 - 03:53 PM

Use an external javascript file. Save the below as banner.js
image = new Array
image[1]="images/TopBanner1.jpg"
image[2]="images/TopBanner2.jpg"
image[3]="images/TopBanner3.jpg"
image[4]="images/TopBanner4.jpg"
image[5]="images/TopBanner5.jpg"
image[6]="images/TopBanner6.jpg"
image[7]="images/TopBanner7.jpg"
image[8]="images/TopBanner8.jpg"
image[9]="images/TopBanner9.jpg"
image[10]="images/FlowersBanner.jpg"
// Create a random number between 1 and ten
random_num = (Math.round((Math.random()*9)+1))

document.write("<img src=\"" + image[random_num] + "\">");

Use it like this (on every page):
<h1 id="siteName" align="center"><script type="text/javascript" src="banner.js"></script></h1>

Legend has it that reading the manual never killed anyone.
My site

#3 ptex

ptex
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 22 May 2006 - 04:20 PM

Wow I'm dumb thanks but this can be done in PHP as a include right? Sorry for the noob question and thanks.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 May 2006 - 04:30 PM

[!--quoteo(post=376070:date=May 22 2006, 12:20 PM:name=ptex)--][div class=\'quotetop\']QUOTE(ptex @ May 22 2006, 12:20 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
... but this can be done in PHP as a include right? Sorry for the noob question and thanks.
[/quote]
Yes, but there's no obvious benefit to that compared to what I gave you.

If that's what you really want to do, then take all of the code you originally posted and save it as do_banner.php and use it like this on every page:

<?php
include("do_banner.php");
?>

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users