View Full Version : php, javascript rotation-beginner to javascript

12-10-2006, 05:30 AM
I found this javascript code and want to learn more, found ajax kinda interesting too... but, with this code, I figured i could get my php banner script to rotate with seconds, instead of refresh,, well, it worked, but dont know how to get it to let me use multiple spots in one page, and not sure how its going to work with my using different size banner, and ... lol... how i can do away with the html code to view the banner, and use something different... will explain more on that later...

when you click a banner, and hit back in the browser it say error in the bottom left corner of IE, where it would normally say "Done" for the page to be loaded,,, but seams to still work ok... my major problem is that it will only let me post this one banner at the top of my page,, If I try to make copies of it and have it load another banner it has conflicts with eachother, so until I get to learning javascript more,,, think this is out of the question... because I need to post the 120x90 ads on the right no matter what,,, on my site they are more for local ads, and its how my site is designed... hate to redesign it again...

here the javascript, php code which is pulled by the include:

<script language="JavaScript">
var bannerArray = new Array();
var myCount=0;

This is the start of the php code I developed which pulles the information from a text file, and loads what I need for the banners. it also calculates how many monthes the banner spot was purchased, monthly because I dont like dealing with impressions, views or whatever,, just pay monthly, easy, fast, and other people know what they get if they are not used to advertising on the internet....


$fd =fopen ($_REQUEST[s].".txt", "r");
if ($fd)
$line = null;
while (!feof ($fd))
if (!$line)

// Skip header I skip one line of the text file, so the text file has how to input the information into the text file, want to make administration script later,, might want mysql later too.. but text file is how I started with...

$line = fgets($fd, 4096);
$line = fgets($fd, 4096);
if (strlen($line) > 10)
list($id,$d_start,$dur,$url,$ban,$alt,$tar,$c_name,$c_email,$c_phone) = split (",", $line, 9);
list($m,$d,$y)= split ("\/", $d_start, 3);
list($dd,$mm,$yyyy) = split("-",date("d-m-Y",time()));
$today = mktime(0, 0, 0, $mm, $dd, $yyyy);

$d_end = mktime(0, 0, 0, $m+$dur, $d, $y);
$ds = date('m/d/Y',$d_end);
if($d_end >= $today){
$c = count($line);
echo "bannerArray[$id] = \"<A HREF='".$url."' target='".$tar."'><IMG SRC='".$ban."' border='0' alt='".$alt."'></A>\";\n";


and back to the javascript I borrowed...


function bannerRotate() {

if(myCount > bannerArray.length-1){myCount=0;}

if (document.all){

else if (document.layers){

setTimeout("bannerRotate()", 3000);
// -->

Then I have to use this above the include,, because not my code,,, to place in the html.. I dont like using this, and if possible would like to change,,, maybe use something like <div id=banner s=728x90></div>

<font face="Tahoma" size="2">
<ilayer id="l1"></p>
<layer id="l2">
<div id="l1">
<div id="l3" style="position:relative">

is there any suggestions on how I can do this, or someone might be able to tell me where I can get a better, shorter javascript to use,, because the only reason I want the javascript is to rotate the ads in seconds, and be able to place more than one banner on a single page... kinda like this:

<table border="0" cellpadding="0" cellspacing="0" width="100%" height="90"><tr><td align="center" valign="bottom">

<div id=banner s=120x90></div>
</td><td align="center" valign="middle">

<div id=banner s=728x90></div>
</td><td align="center" valign="bottom">

<div id=banner s=120x90></div>


right now dont really have time to learn,, Im willing to redew all the javascript altogether, but the php ive come kinda stuck with,,, kinda hard to recode that...but have to get this script up as soon as possible, but want to learn more because found many things while searching on this feature Id like to try with my php script to make them a lil better,,, and want to learn more about this ajax because now there is another system out there to integrate it more with php... Provides PHP and JavaScript libraries for performing AJAX,,, which sounded interesting, and have it on my home server, now, just cant explain much about it yet...lol

Philip M
12-10-2006, 09:29 AM
"If I try to make copies of it and have it load another banner it has conflicts with each other"

This is a clunky way to do it, and your code is pretty ancient, but you can rename all functions and variables to avoid conflicts e.g.

var bannerArray1
var bannerArray2
var myCount1
var myCount2

function bannerRotate1()
function bannerRotate2()

But who wants to visit a site stuffed with banners???

12-10-2006, 05:58 PM
so whats clunky, the javascript? lol... the php is my own,,, its all I know,, course ive been working with php for almost 5 years,, and have been out of it for almost 1 year until recently since about a month ago...

thanks for the input,, tell me,, what would you change,, I just want something right now to post on the site, want to redew it later to try to tighten it up, hopefully make it all work with one script, and turn it into mysql, and a good administration system...

a site stuffed with banners,,, well,, let me put it this way,, the site is for a local community that has so many business's, and more information for the community to deal with things,,, like free classifieds, and such,,, the advertising is only their to make revenue until we can find a better way,,, the main thing is that with everything they are going to get for free with the site,, dont think they will even look at the banners anyhow,, but all business's advertising are local where people shop anyhow... like the local food stores... clothing stores,, and hope to get local advertising for events, car shows, and entertainment like bands playing at certain clubs... but if no site plastered with banners,, then no site..
how else to keep it up? and that is a legit question,, any suggestions,, great,,, cuz i need them,,, the main thing is, wanted to keep as much as possible free for the visitors...