Webocreation

Tuesday, December 21, 2010

Dynamic Image rollover from the database

<SCRIPT LANGUAGE="JavaScript">

<!--

var dimages=new Array();

var dimages1=new Array();

 



<?

$banners=$all->get_banner();



foreach($banners as $key => $banner)

{

?>

var numImages = <?php echo count($banners); ?>



dimages[<?php echo $key; ?>]=new Image();

dimages[<?php echo $key; ?>].src="<?=UPLOAD_BANNER_DIR.$banner['image']?>";

<? }?>

 

 

var curImage=-1;

function swapPicture()

{

if (document.images)

{

var nextImage=curImage+1;

if (nextImage>=numImages)

nextImage=0;

if (dimages[nextImage] && dimages[nextImage].complete)

{

var target=0;

if (document.images.myImage)

target=document.images.myImage;

if (document.all && document.getElementById("myImage"))

target=document.getElementById("myImage");



// make sure target is valid. It might not be valid

// if the page has not finished loading

if (target)

{

target.src=dimages[nextImage].src;

curImage=nextImage;

}

setTimeout("swapPicture()", 1000);

}

else

{

setTimeout("swapPicture()", 500);

}

}

}

setTimeout("swapPicture()", 1000);

//-->

</SCRIPT>

<div class="add_box">

<div class="add_top"></div>

<div class="add_mid">

<div align="center"><img src="images/add.gif" />



<?php



$banners=$all->get_banner_one();

foreach($banners as $banner)

{

?>

<? if($banner['banner_type']=="image"){?>

<img src="<?=UPLOAD_BANNER_DIR.$banner['image']?>" alt="" border="0" width="500px" height="200" ID="myImage" NAME="myImage" />

<? } else { echo $banner['code'];}?>

<?

}?>

</div>

</div>

<div class="add_btm"></div>

</div>

No comments:

Post a Comment