Hi guys, I'm trying to implement some code in an include and it seems to be writing out the actual code instead of just showing the adsense. I'm wondering if perhaps the code in the include file is missing something to stop the rest from showing? I've attached it below: <?php $rand = rand(1,2); if ($rand == 1) //Alex's Code print '<script type="text/javascript"><!-- google_ad_client = "pub-3397443514176608"; /* 468x60, Vitality Post created 16/09/08 */ google_ad_slot = "6505292334"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; elseif ($rand == 2) //Quail's code print '<script type="text/javascript"><!-- google_ad_client = "pub-8340578488567063"; /* Vitality Post */ google_ad_slot = "1305793207"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; ?> Code (markup): You can see the error on this page: http://tinyurl.com/6xsn2m Thanks for any help on this!
Try changing the code to this: <?php $rand = rand(1,2); if ($rand == 1) { //Alex's Code ?> <script type="text/javascript"><!-- google_ad_client = "pub-3397443514176608"; /* 468x60, Vitality Post created 16/09/08 */ google_ad_slot = "6505292334"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <?php } elseif ($rand == 2) { //Quail's code ?> <script type="text/javascript"><!-- google_ad_client = "pub-8340578488567063"; /* Vitality Post */ google_ad_slot = "1305793207"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <?php } ?> Code (markup):
try - <?php $rand = rand(1,2); if ($rand == "1") echo ' <script type="text/javascript"><!-- google_ad_client = "pub-3397443514176608"; /* 468x60, Vitality Post created 16/09/08 */ google_ad_slot = "6505292334"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; elseif ($rand == 2) //Quail's code print '<script type="text/javascript"><!-- google_ad_client = "pub-8340578488567063"; /* Vitality Post */ google_ad_slot = "1305793207"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; ?> PHP:
<?php $rand = rand(1,2); /// if ($rand == "1") { echo ' <script type="text/javascript"><!-- google_ad_client = "pub-3397443514176608"; /* 468x60, Vitality Post created 16/09/08 */ google_ad_slot = "6505292334"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } elseif ($rand == 2) { echo '<script type="text/javascript"><!-- google_ad_client = "pub-8340578488567063"; /* Vitality Post */ google_ad_slot = "1305793207"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> '; } ?> PHP:
this works fine for me - <?php $rand = rand(1,2); /// if ($rand == "1") { echo ' <script type="text/javascript"><!-- google_ad_client = "pub-3397443514176608"; /* 468x60, Vitality Post created 16/09/08 */ google_ad_slot = "6505292334"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; } elseif ($rand == "2") { echo ' <script type="text/javascript"><!-- google_ad_client = "pub-8340578488567063"; /* Vitality Post */ google_ad_slot = "1305793207"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; } ?> PHP: