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? Quote 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.. Quote 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 Quote 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'? Quote 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>"; } Quote 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. Quote 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%. Quote 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 Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.