Sean_J Posted January 29, 2008 Share Posted January 29, 2008 Hello everyone Im looking for some help on rotating banners, I've searched the internet and found nothing. Basically on my homepage I want to have six banners positioned down the right hand side of the page. (All visable at the same time) for e.g Banner1.jpg Banner2.jpg Banner3.jpg Banner4.jpg Banner5.jpg Banner6.jpg Once the page has been refreshed I would like the banners to change position, for e.g Banner2.jpg Banner3.jpg Banner4.jpg Banner5.jpg Banner6.jpg Banner1.jpg Bassicly each banner will have its turn of being at the top of the page. Can anyone please tell me how I go about doing this, or if there is a certain script I could use. Regards Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/ Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 you got any code for this ?? you can do it in php or even in javascript which on do you prefer Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452156 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 try this code <?php $arrBanner = range(1,6); shuffle($arrBanner); for ($i=0;$i<count($arrBanner);$i++) { echo "<img src='Banner{$arrBanner[$i]}.jpg'><BR>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452157 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Thank you for your reply, to be hoesnt I only us HTML and CSS at the moment. Im starting to learn PHP and MYSQL soon. How would I use the code that you have given me, sorry about this. Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452159 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 if you have a php server running just put the code up there and it will start working I am trying to cook up a javascript alternative... Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452160 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Thank you very much. Like I said ive searched the internet and found nothing. All the scripts ive found only show one banner at a time. Not all at the same time just in different possitions. Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452169 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 here you go it took a long time to cook up <script> var arrBanner = new Array(); function random(arrAvoid,intMax) { var intRand = Math.ceil(Math.random()*intMax); if (!inArray(arrAvoid,intRand)) { arrBanner.push(intRand); } else { random(arrAvoid,intMax); } } function inArray(arrArray,strSearch) { for (strKey in arrArray) { if (arrArray[strKey]==strSearch) { return true; } } return false } for (i=0;i<6;i++) { random(arrBanner,6); } for (strKey in arrBanner) { document.write("<img src='Banner"+arrBanner[strKey]+".jpg'><BR>"); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452175 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Thank you very much for taking the time to make me that code, your a life saver. Rerards Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452199 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 tell me how it works, Glad to be of help Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452202 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 It works great thank you, Is it possible to make the banners into links using Java script? Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452206 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 Yes give me a moment while I write up something.... Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452210 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Out of all the forums ive been on, this has to be the best. Im actually receiving help Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452212 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 here you go <script> var arrBanner = new Array(); var arrLinks = new Array(); arrLinks[1] = "Link 1"; arrLinks[2] = "Link 2"; arrLinks[3] = "Link 3"; arrLinks[4] = "Link 4"; arrLinks[5] = "Link 5"; arrLinks[6] = "Link 6"; function random(arrAvoid,intMax) { var intRand = Math.ceil(Math.random()*intMax); if (!inArray(arrAvoid,intRand)) { arrBanner.push(intRand); } else { random(arrAvoid,intMax); } } function inArray(arrArray,strSearch) { for (strKey in arrArray) { if (arrArray[strKey]==strSearch) { return true; } } return false } for (i=0;i<6;i++) { random(arrBanner,6); } for (strKey in arrBanner) { document.write("<a href=\""+arrLinks[arrBanner[strKey]]+"\"><img src='Banner"+arrBanner[strKey]+".jpg' border=0><BR>"); } </script> where its Link 1 put the link for banner1.jpg and so on... hope its helpful.. I see your new to the forum.. Welcome to PhpFreaks Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452215 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Yes im new to the site, thank you for the welcome. That coding works great so thank you. Regards Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452249 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Just a quick one, do my banners have to be jpeg's? What would happen if one was a gif? Regards Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452265 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 just a minute I'll write you something really dynamic Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452267 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 I bet you think im a right pain in the arse Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452268 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 No not at all, I love to help out fellow programmers, here you go new and improved <script> var arrBanner = new Array(); var arrLinks = new Array(); var arrBannerFiles = new Array(); arrBannerFiles[1] = "Banner1.jpg"; arrBannerFiles[2] = "Banner2.jpg"; arrBannerFiles[3] = "Banner3.jpg"; arrBannerFiles[4] = "Banner4.jpg"; arrBannerFiles[5] = "Banner5.jpg"; arrBannerFiles[6] = "Banner6.jpg"; arrLinks[1] = "Link 1"; arrLinks[2] = "Link 2"; arrLinks[3] = "Link 3"; arrLinks[4] = "Link 4"; arrLinks[5] = "Link 5"; arrLinks[6] = "Link 6"; function random(arrAvoid,intMax) { var intRand = Math.ceil(Math.random()*intMax); if (!inArray(arrAvoid,intRand)) { arrBanner.push(intRand); } else { random(arrAvoid,intMax); } } function inArray(arrArray,strSearch) { for (strKey in arrArray) { if (arrArray[strKey]==strSearch) { return true; } } return false } for (i=0;i<6;i++) { random(arrBanner,6); } for (strKey in arrBanner) { document.write("<a href=\""+arrLinks[arrBanner[strKey]]+"\"><img src='"+arrBannerFiles[arrBanner[strKey]]+"' border=0><BR>"); } </script> now your filename can be anything... just keep the consistency, also I added intNumberOfBanners for the number of banner incase you want to remove or add another one just keep the number consistent with links and filenames hope its helpful Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452271 Share on other sites More sharing options...
Sean_J Posted January 29, 2008 Author Share Posted January 29, 2008 Thats great, I think thats all haha Cheers mate Sean Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452275 Share on other sites More sharing options...
rajivgonsalves Posted January 29, 2008 Share Posted January 29, 2008 Welcome glad to be of help ... Quote Link to comment https://forums.phpfreaks.com/topic/88354-banner-help/#findComment-452278 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.