drisate Posted August 25, 2009 Share Posted August 25, 2009 Hey guys i need to create a page with a total of 8 banners one under an other rotating ... I am having a very hard time making Javascript and PHP work to gether. I managed to create this but the rotating is not working and i gething out of option. the Javascript code works greate with out PHP ... but when i try to make it dynamique with MySQL info thats where it breaks... what did i do wroung? PHP code /////////////////////////////////////////////// ?> <script type="text/javascript"> <?php $counter = 1; while ( $counter <= 8 ) { ?> var imgs<?=$counter?> = new Array("<?php $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $img = $img."http://proprio-media.com/administrator/uploads/$pub[photo], "; } echo substr($img, 0, -2); unset($img); ?>"); var lnks<?=$counter?> = new Array("<?php $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $url = $url."http://$pub[url], "; } echo substr($url, 0, -2); unset($url); ?>"); var alt<?=$counter?> = new Array("<?php $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $alt = $alt."$pub[url], "; } echo substr($alt, 0, -2); unset($alt); ?>"); var currentAd<?=$counter?> = 0; var imgCt<?=$counter?> = 3; function cycle<?=$counter?>() { if (currentAd<?=$counter?> == imgCt<?=$counter?>) { currentAd<?=$counter?> = 0; } var banner<?=$counter?> = document.getElementById('adBanner<?=$counter?>'); var link<?=$counter?> = document.getElementById('adLink<?=$counter?>'); banner<?=$counter?>.src=imgs<?=$counter?>[currentAd<?=$counter?>] banner<?=$counter?>.alt=alt<?=$counter?>[currentAd<?=$counter?>] document.getElementById('adLink<?=$counter?>').href=lnks<?=$counter?>[currentAd<?=$counter?>] currentAd<?=$counter?>++; } window.setInterval("cycle<?=$counter?>()",10000); <?php $counter++; } ?> </script> <? $counter = 1; while ( $counter <= 8 ) { $pu = @mysql_fetch_assoc(@mysql_query("SELECT * FROM pub where num='$counter' order by id asc limit 1")); ?> <a href="http://www.<?=$pu[url]?>" id="adLink<?=$counter?>" target="_top"> <img src="http://proprio-media.com/administrator/uploads/<?=$pu[photo]?>" id="adBanner<?=$counter?>" border="0"></a> <br><br> <?php $counter++; } /////////////////////////////////////////////// HTML OUTPUT <script type="text/javascript"> var imgs1 = new Array("http://proprio-media.com/administrator/uploads/473253laurentide2.jpg, http://proprio-media.com/administrator/uploads/860749150x250-02.jpg, http://proprio-media.com/administrator/uploads/636470laval3.jpg"); var lnks1 = new Array("http://, http://, http://"); var alt1 = new Array(", , "); var currentAd1 = 0; var imgCt1 = 3; function cycle1() { if (currentAd1 == imgCt1) { currentAd1 = 0; } var banner1 = document.getElementById('adBanner1'); var link1 = document.getElementById('adLink1'); banner1.src=imgs1[currentAd1] banner1.alt=alt1[currentAd1] document.getElementById('adLink1').href=lnks1[currentAd1] currentAd1++; } window.setInterval("cycle1()",10000); var imgs2 = new Array("http://proprio-media.com/administrator/uploads/835152Rive-Sud4.jpg, http://proprio-media.com/administrator/uploads/519177Rive-Sud4.jpg, http://proprio-media.com/administrator/uploads/869400laurentide4.jpg"); var lnks2 = new Array("http://, http://, http://"); var alt2 = new Array(", , "); var currentAd2 = 0; var imgCt2 = 3; function cycle2() { if (currentAd2 == imgCt2) { currentAd2 = 0; } var banner2 = document.getElementById('adBanner2'); var link2 = document.getElementById('adLink2'); banner2.src=imgs2[currentAd2] banner2.alt=alt2[currentAd2] document.getElementById('adLink2').href=lnks2[currentAd2] currentAd2++; } window.setInterval("cycle2()",10000); var imgs3 = new Array("http://proprio-media.com/administrator/uploads/317794Rive-Sud2.jpg, http://proprio-media.com/administrator/uploads/214150laval3.jpg, http://proprio-media.com/administrator/uploads/370317150x250-07.jpg"); var lnks3 = new Array("http://, http://, http://"); var alt3 = new Array(", , "); var currentAd3 = 0; var imgCt3 = 3; function cycle3() { if (currentAd3 == imgCt3) { currentAd3 = 0; } var banner3 = document.getElementById('adBanner3'); var link3 = document.getElementById('adLink3'); banner3.src=imgs3[currentAd3] banner3.alt=alt3[currentAd3] document.getElementById('adLink3').href=lnks3[currentAd3] currentAd3++; } window.setInterval("cycle3()",10000); var imgs4 = new Array("http://proprio-media.com/administrator/uploads/897292montreal1.jpg, http://proprio-media.com/administrator/uploads/386411Rive-Sud2.jpg"); var lnks4 = new Array("http://, http://"); var alt4 = new Array(", "); var currentAd4 = 0; var imgCt4 = 3; function cycle4() { if (currentAd4 == imgCt4) { currentAd4 = 0; } var banner4 = document.getElementById('adBanner4'); var link4 = document.getElementById('adLink4'); banner4.src=imgs4[currentAd4] banner4.alt=alt4[currentAd4] document.getElementById('adLink4').href=lnks4[currentAd4] currentAd4++; } window.setInterval("cycle4()",10000); var imgs5 = new Array("http://proprio-media.com/administrator/uploads/534149Rive-Sud1.jpg, http://proprio-media.com/administrator/uploads/"); var lnks5 = new Array("http://, http://"); var alt5 = new Array(", "); var currentAd5 = 0; var imgCt5 = 3; function cycle5() { if (currentAd5 == imgCt5) { currentAd5 = 0; } var banner5 = document.getElementById('adBanner5'); var link5 = document.getElementById('adLink5'); banner5.src=imgs5[currentAd5] banner5.alt=alt5[currentAd5] document.getElementById('adLink5').href=lnks5[currentAd5] currentAd5++; } window.setInterval("cycle5()",10000); var imgs6 = new Array("http://proprio-media.com/administrator/uploads/646964laurentide2.jpg, http://proprio-media.com/administrator/uploads/693145laval1.jpg"); var lnks6 = new Array("http://, http://"); var alt6 = new Array(", "); var currentAd6 = 0; var imgCt6 = 3; function cycle6() { if (currentAd6 == imgCt6) { currentAd6 = 0; } var banner6 = document.getElementById('adBanner6'); var link6 = document.getElementById('adLink6'); banner6.src=imgs6[currentAd6] banner6.alt=alt6[currentAd6] document.getElementById('adLink6').href=lnks6[currentAd6] currentAd6++; } window.setInterval("cycle6()",10000); var imgs7 = new Array("http://proprio-media.com/administrator/uploads/321567laval2.jpg, http://proprio-media.com/administrator/uploads/304925laurentide3.jpg"); var lnks7 = new Array("http://, http://"); var alt7 = new Array(", "); var currentAd7 = 0; var imgCt7 = 3; function cycle7() { if (currentAd7 == imgCt7) { currentAd7 = 0; } var banner7 = document.getElementById('adBanner7'); var link7 = document.getElementById('adLink7'); banner7.src=imgs7[currentAd7] banner7.alt=alt7[currentAd7] document.getElementById('adLink7').href=lnks7[currentAd7] currentAd7++; } window.setInterval("cycle7()",10000); var imgs8 = new Array("http://proprio-media.com/administrator/uploads/228557montreal3.jpg, http://proprio-media.com/administrator/uploads/829490montreal2.jpg"); var lnks8 = new Array("http://, http://"); var alt8 = new Array(", "); var currentAd8 = 0; var imgCt8 = 3; function cycle8() { if (currentAd8 == imgCt8) { currentAd8 = 0; } var banner8 = document.getElementById('adBanner8'); var link8 = document.getElementById('adLink8'); banner8.src=imgs8[currentAd8] banner8.alt=alt8[currentAd8] document.getElementById('adLink8').href=lnks8[currentAd8] currentAd8++; } window.setInterval("cycle8()",10000); </script> <a href="http://www." id="adLink1" target="_top"> <img src="http://proprio-media.com/administrator/uploads/473253laurentide2.jpg" id="adBanner1" border="0"></a> <br><br> <a href="http://www." id="adLink2" target="_top"> <img src="http://proprio-media.com/administrator/uploads/835152Rive-Sud4.jpg" id="adBanner2" border="0"></a> <br><br> <a href="http://www." id="adLink3" target="_top"> <img src="http://proprio-media.com/administrator/uploads/317794Rive-Sud2.jpg" id="adBanner3" border="0"></a> <br><br> <a href="http://www." id="adLink4" target="_top"> <img src="http://proprio-media.com/administrator/uploads/897292montreal1.jpg" id="adBanner4" border="0"></a> <br><br> <a href="http://www." id="adLink5" target="_top"> <img src="http://proprio-media.com/administrator/uploads/534149Rive-Sud1.jpg" id="adBanner5" border="0"></a> <br><br> <a href="http://www." id="adLink6" target="_top"> <img src="http://proprio-media.com/administrator/uploads/646964laurentide2.jpg" id="adBanner6" border="0"></a> <br><br> <a href="http://www." id="adLink7" target="_top"> <img src="http://proprio-media.com/administrator/uploads/321567laval2.jpg" id="adBanner7" border="0"></a> <br><br> <a href="http://www." id="adLink8" target="_top"> <img src="http://proprio-media.com/administrator/uploads/228557montreal3.jpg" id="adBanner8" border="0"></a> <br><br> Quote Link to comment Share on other sites More sharing options...
drisate Posted August 25, 2009 Author Share Posted August 25, 2009 hmm looks like i finaly made it ... it was the javascript array lol var imgs<?=$counter?> = new Array(<?php unset($img); $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $img = $img.'"http://proprio-media.com/administrator/uploads/'.$pub[photo].'", '; } echo substr($img, 0, -2); ?>); var lnks<?=$counter?> = new Array(<?php unset($url); $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $url = $url.'"http://'.$pub[url].'", '; } echo substr($url, 0, -2); ?>); var alt<?=$counter?> = new Array(<?php unset($alt); $select = mysql_query("SELECT * FROM pub where num='$counter'") or die(mysql_error()); while ($pub = mysql_fetch_array($select)) { $alt = $alt.'"'.$pub[photo].'", '; } echo substr($alt, 0, -2); ?>); Quote Link to comment 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.