2014-09-24 49 views
-2
<div id="leaderboardAd"> 
    <?php 
     //THIS SCRIPT GENERATES A RANDOM AD. 

     $randomAd = rand(1,2); 

     switch($randonAd) { 
      case "1": 
       $adNumber = "/contributors.php"; 
       $pngNumber = "/images/contributorsAd.png"; 
      case "2": 
       $adNumber = "http://www.cameronmontesano.com"; 
       $pngNumber = "/images/cameronmontesano-com.png"; 
      default: 
       $adNumber = "/contributors.php"; 
       $pngNumber = "/images/contributorsAd.png"; 
     } 
    ?> 
    <a href="<?php echo $adNumber ?>"> 
     <img src="<?php echo $pngNumber ?>" width="720px" height="90px" /> 
    </a> 
</div> 

它只顯示默認廣告。PHP隨機廣告不能用?

+0

沒有php強制會處理該問題 – 2014-09-24 14:39:51

+2

[PHP:switch](http://php.net/switch):*如果您沒有在案例的聲明列表末尾寫入break語句,PHP將繼續執行以下情況的陳述* – 2014-09-24 14:41:31

回答

1

或許,如果你花更少的時間坐在你o關鍵,實際上看你的代碼,你會看到這一點:

$randomAd = rand(1,2); 
      ^---- 
    switch($randonAd) { 
       ^---- spot the difference. 
0

你的switch語句中使用了$ randonAd但要設置隨機變量爲$ randomAd。