Jump to content

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/
Share on other sites

Use an external javascript file. Save the below as banner.js
[code]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] + "\">");[/code]

Use it like this (on every page):
[code]
<h1 id="siteName" align="center"><script type="text/javascript" src="banner.js"></script></h1>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/#findComment-37977
Share on other sites

[!--quoteo(post=376070:date=May 22 2006, 12:20 PM:name=ptex)--][div class=\'quotetop\']QUOTE(ptex @ May 22 2006, 12:20 PM) [snapback]376070[/snapback][/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 [b]all[/b] of the code you originally posted and save it as do_banner.php and use it like this on every page:

[code]<?php
include("do_banner.php");
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/#findComment-37986
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.