Hypermx Posted August 27, 2009 Share Posted August 27, 2009 Hey. I have made a code, so that everytime you load the page, it randomly selects wether it sould be an ad or a picture to be there. I think Im allmost finished with the code, But it have some errors. Example, that when it sould show an ad it shows nothing. I will list 2 files in here, The functions.php and the Index.php. Functions.php <?php function display_adsense() { echo " <script type='text/javascript'><!-- google_ad_client = 'pub-7631840574101908'; /* 300x250, oprettet 21-08-09 */ google_ad_slot = '1626493265'; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'> </script>"; } function random_ad() { echo " <script language='JavaScript'> images = new Array(2); images[0] = '<?php display_adsense() ?>'; images[1] = '<img src=wp-content/themes/wp-symisun/images/ad_test_1.PNG></img>'; index = Math.floor(Math.random() * images.length); document.write(images[index]); </script>"; } ?> Index.php <?php random_ad() ?> I have not posted the Fully index.php or the fully functions.php, But this is the only thing that haves an error. Can anybody tell me what the problem is? Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/ Share on other sites More sharing options...
Hypermx Posted August 27, 2009 Author Share Posted August 27, 2009 Don't be shy, I won't bite No seriously, Help me.. Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-907921 Share on other sites More sharing options...
Hypermx Posted August 28, 2009 Author Share Posted August 28, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-908013 Share on other sites More sharing options...
Hypermx Posted August 28, 2009 Author Share Posted August 28, 2009 Omg, It can't be this hard'? Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-908234 Share on other sites More sharing options...
DavidAM Posted August 28, 2009 Share Posted August 28, 2009 your assignment in the javascript is openning a php block, but you are in the middle of an echo in php. I think you need to just close the string, call the function, then open the string back up. function random_ad() { echo " <script language='JavaScript'> images = new Array(2); images[0] = '" . display_adsense() . "'; images[1] = '<img src=wp-content/themes/wp-symisun/images/ad_test_1.PNG></img>'; index = Math.floor(Math.random() * images.length); document.write(images[index]); </script>"; } Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-908298 Share on other sites More sharing options...
Hypermx Posted August 28, 2009 Author Share Posted August 28, 2009 Thanks, Im going to test it now. Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-908662 Share on other sites More sharing options...
Hypermx Posted August 29, 2009 Author Share Posted August 29, 2009 Well, Ive just tested it and came up with the result that the adsense displayses now, But now also the other picture displays at the same time in a procent of 50%. Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-908744 Share on other sites More sharing options...
Hypermx Posted August 29, 2009 Author Share Posted August 29, 2009 bump Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-909084 Share on other sites More sharing options...
Hypermx Posted August 31, 2009 Author Share Posted August 31, 2009 bump Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-909610 Share on other sites More sharing options...
Hypermx Posted September 2, 2009 Author Share Posted September 2, 2009 bump Link to comment https://forums.phpfreaks.com/topic/172192-random-image-picture-and-adsense/#findComment-910955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.