dongbamage
Programmer
Hi peeps,
I made a little script that calls photo's from my MySQL db, then passes them from a PHP array to JS.
The problem I'm having is although it works if run directly, when i add it to my mainpage, it doesn't work...
Anyone got any ideas?
Here's my code..
<?
include_once
$arraycount=0;
$counter++;
$counter2=($counter+1);
$counter3=($counter+2);
$sql= "select StockID, Photo, StockName from stock";
$result = mysql_query($sql) or die ("dead");
while($row=mysql_fetch_array($result))
{
$image=$row["Photo"]."catthumb.gif";
$StockID=$row["StockID"];
$linkStockID=$stockID;
$StockName=$row["StockName"];
$array[$arraycount]=$image;
$arraycount++;
$array[$arraycount]=$StockID;
#echo ("<a href='?Prodlink=ProductShow?id=$StockID'>".
#"<img src='$image'> </a>");
$arraycount++;
}
?>
<script language="JavaScript">
function adArray() {
for (i=0; i*2<adArray.arguments.length; i++) {
this = new Object();
this.src = adArray.arguments[i*2];
this.href = adArray.arguments[i*2+1];
}
this.length = i;
}
function getAdNum() {
dat = new Date();
dat = (dat.getTime()+"").charAt(8);
if (dat.length == 1)
ad_num = dat%ads.length;
else
ad_num = 0;
return ad_num;
}
var ads=new adArray("<?=implode("\",\"", $array); ?>");
var ad_num = getAdNum();
document.write('<CENTER><TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0><TR><TD '
+'ALIGN=CENTER><FONT SIZE=2 FACE=Arial><B>Click for details! '
+'</FONT></TD><TR></TR><TD><A HREF="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad></A></TD></TR><TR></TR><TD><A HREF="'+ads[ad_num+1].href+'"><IMG SRC="'+ads[ad_num+1].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad1></A></TD></TR><TR></TR><TD><A HREF="'+ads[ad_num+2].href+'"><IMG SRC="'+ads[ad_num+2].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad2></A></TD></TR></TABLE></CENTER>');
link_num = document.links.length-1;
document.js_ad.src = ads[ad_num].src;
document.js_ad1.src = ads[ad_num+1].src;
document.js_ad2.src = ads[ad_num+2].src;
document.links[0].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num].href;
document.links[1].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+1].href;
document.links[2].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+2].href;
function rotateSponsor() {
if (document.images) {
ad_num = (ad_num+1)%ads.length;
document.js_ad.src = ads[ad_num].src;
document.js_ad1.src = ads[ad_num+1].src;
document.js_ad2.src = ads[ad_num+2].src;
document.links[0].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num].href;
document.links[1].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+1].href;
document.links[2].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+2].href;
setTimeout("rotateSponsor()",5000);
}
}
setTimeout("rotateSponsor()",5000);
// -->
</script>
I made a little script that calls photo's from my MySQL db, then passes them from a PHP array to JS.
The problem I'm having is although it works if run directly, when i add it to my mainpage, it doesn't work...
Anyone got any ideas?
Here's my code..
<?
include_once
$arraycount=0;
$counter++;
$counter2=($counter+1);
$counter3=($counter+2);
$sql= "select StockID, Photo, StockName from stock";
$result = mysql_query($sql) or die ("dead");
while($row=mysql_fetch_array($result))
{
$image=$row["Photo"]."catthumb.gif";
$StockID=$row["StockID"];
$linkStockID=$stockID;
$StockName=$row["StockName"];
$array[$arraycount]=$image;
$arraycount++;
$array[$arraycount]=$StockID;
#echo ("<a href='?Prodlink=ProductShow?id=$StockID'>".
#"<img src='$image'> </a>");
$arraycount++;
}
?>
<script language="JavaScript">
function adArray() {
for (i=0; i*2<adArray.arguments.length; i++) {
this = new Object();
this.src = adArray.arguments[i*2];
this.href = adArray.arguments[i*2+1];
}
this.length = i;
}
function getAdNum() {
dat = new Date();
dat = (dat.getTime()+"").charAt(8);
if (dat.length == 1)
ad_num = dat%ads.length;
else
ad_num = 0;
return ad_num;
}
var ads=new adArray("<?=implode("\",\"", $array); ?>");
var ad_num = getAdNum();
document.write('<CENTER><TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0><TR><TD '
+'ALIGN=CENTER><FONT SIZE=2 FACE=Arial><B>Click for details! '
+'</FONT></TD><TR></TR><TD><A HREF="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad></A></TD></TR><TR></TR><TD><A HREF="'+ads[ad_num+1].href+'"><IMG SRC="'+ads[ad_num+1].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad1></A></TD></TR><TR></TR><TD><A HREF="'+ads[ad_num+2].href+'"><IMG SRC="'+ads[ad_num+2].src+'" '
+'WIDTH="100" HEIGHT="60" BORDER=0 name=js_ad2></A></TD></TR></TABLE></CENTER>');
link_num = document.links.length-1;
document.js_ad.src = ads[ad_num].src;
document.js_ad1.src = ads[ad_num+1].src;
document.js_ad2.src = ads[ad_num+2].src;
document.links[0].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num].href;
document.links[1].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+1].href;
document.links[2].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+2].href;
function rotateSponsor() {
if (document.images) {
ad_num = (ad_num+1)%ads.length;
document.js_ad.src = ads[ad_num].src;
document.js_ad1.src = ads[ad_num+1].src;
document.js_ad2.src = ads[ad_num+2].src;
document.links[0].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num].href;
document.links[1].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+1].href;
document.links[2].href = "../fargle2.php?Prodlink=ProductShow?id="+ads[ad_num+2].href;
setTimeout("rotateSponsor()",5000);
}
}
setTimeout("rotateSponsor()",5000);
// -->
</script>