ptex Posted May 22, 2006 Share Posted May 22, 2006 How can I make this <h1 id="siteName" align="center"><script language="JavaScript"><!--image = new Arrayimage[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 tenrandom_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? Quote Link to comment https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/ Share on other sites More sharing options...
AndyB Posted May 22, 2006 Share Posted May 22, 2006 Use an external javascript file. Save the below as banner.js[code]image = new Arrayimage[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 tenrandom_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] Quote Link to comment https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/#findComment-37977 Share on other sites More sharing options...
ptex Posted May 22, 2006 Author Share Posted May 22, 2006 Wow I'm dumb thanks but this can be done in PHP as a include right? Sorry for the noob question and thanks. Quote Link to comment https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/#findComment-37983 Share on other sites More sharing options...
AndyB Posted May 22, 2006 Share Posted May 22, 2006 [!--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]<?phpinclude("do_banner.php");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10190-banner-stored-as-php/#findComment-37986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.