Click to See Complete Forum and Search --> : banner rotation...plz help


raj_2006
08-27-2007, 08:39 AM
Hi All,

I have searched this forum and found a nice code.But the problem is that I want to use php/mysql inside the javascript function and also want to add a url(which is also coming from the db) against every banner.

Here is the javascript:

<script language="javascript" type="text/javascript">
<!--
var arrBanner = new Array();

//here i want to add the banners in array from the mysql db.

arrBanner[0] = 'ban/banner468x60.gif'
arrBanner[1] = 'ban/bcpc-banner-468x60.jpg'
function initSlideShow() {
var preLoad = new Array();
for (var i = 0; i < arrBanner.length; i++) {
preLoad[i] = new Image();
preLoad[i].src = arrBanner[i];
}
var rndId = Math.floor(Math.random()*arrBanner.length);

//here I want to add the urls of each banner

document.write('<img src="'+arrBanner[rndId]+'" name="SlideShow" id="SlideShow" width="468" height="60" />');
window.setInterval('runSlideShow()', slideShowSpeed);
} // initSlideShow.
function runSlideShow(){
rndId = Math.floor(Math.random()*arrBanner.length);
if (document.all){
document.images.SlideShow.style.filter = "blendTrans(duration=2)";
document.images.SlideShow.style.filter = "blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply() ;
}
document.images.SlideShow.src = arrBanner[rndId];
if (document.all){
document.images.SlideShow.filters.blendTrans.Play();
}
} // runSlideShow.
//initSlideShow();
//-->
</script>
<script>initSlideShow();</script>

Please suggest me how can i do it....I dont have much idea about using php/mysql inside the javascript...please help me out...

Thanks for your co-operation in advance.

Raj

Arty Effem
08-27-2007, 01:03 PM
Hi All,

I have searched this forum and found a nice code.But the problem is that I want to use php/mysql inside the javascript function and also want to add a url(which is also coming from the db) against every banner.
You may have seen that code posted on this forum, but nobody will recommend it.
The statement
if (document.all){
document.images.SlideShow.style.filter =condemns it to generate errors on anything but I.E.

Also fading transitions are fine for visual slideshows, but less advisable for image links, as the point at which the href changes may be unclear.

Any script calling itself a 'banner rotator (http://www.hotspot.freeserve.co.uk/scripterlative?rbanner)' will provide the facility to specify URLs.
Generating the parameters with PHP is a matter for another forum.

JPnyc
08-27-2007, 02:14 PM
not so, it will only generate an error in Opera. I believe Opera is the only other browser that understands document.all. Gecko browsers will fail the test and never see that code.

To allow for Opera change the test to :

if (document.all&&!window.opera)

raj_2006
08-27-2007, 02:24 PM
Hi

Thanks for your post.Yes I have looked that url and I want exact the same.

But my problem is that to use php mysql code inside the javascript function to call the banner filename + url values from the mysql db.

How can I do that?

Please suggest.

Thanks,
Raj

raj_2006
08-27-2007, 02:31 PM
not so, it will only generate an error in Opera. I believe Opera is the only other browser that understands document.all. Gecko browsers will fail the test and never see that code.

I have not understood couple of things here:

1.what is Gecko browsers?

2.If Opera understand document.all then is it necessary to write

if (document.all&&!window.opera)

Thanks
Raj

JPnyc
08-27-2007, 05:24 PM
you can't put PHP inside JavaScript, you put the JavaScript inside the PHP, just like you would put HTML to be output to the page by the PHP file. you output it as a string literal, then concatenate it with the PHP statements.

Gecko browsers are Firefox, Netscape, Mozilla Sea monkey, etc. gecko is the name of their rendering engine. Yes, you should add &&!window.opera) to the test so that opera will skip over that code that it will not understand.

I'm going to move this to the PHP forum so you'll get the kind of answers you need .

Arty Effem
08-27-2007, 06:23 PM
not so, it will only generate an error in Opera. I believe Opera is the only other browser that understands document.all. Gecko browsers will fail the test and never see that code.
So. Gecko browsers do understand document.all in quirks mode.

My test would be:
if(document.images[0].filters && document.images[0].filters.blendTrans)
...

raj_2006
08-28-2007, 01:36 AM
Hi

Thanks for moving the thread here.

I will try your suggestion means to use javascript inside php and will let you know about the o/p.

Thanks again

Raj

raj_2006
08-29-2007, 02:31 AM
Hi

I have started with this:

echo "<script language=\"javascript\" type=\"text/javascript\">
<?
echo "var slideShowSpeed = 5000"; // Set slideShowSpeed (milliseconds)
echo "var crossFadeDuration = 3"; // Duration of crossfade (seconds).
echo "var arrBanner = new Array()";

At this point i have become stucked how to make an php made javascript array...:confused:
.................................................
.................................................

ALso how can i run a sql loop using a javascript variable which doesnot start with $.

Not getting any clue...........Please suggest me....

Regards,
Raj

raj_2006
08-30-2007, 12:48 AM
Can I have some hints only...:)

Thanks
Raj