2017-07-28 19 views
-5

私は、サイトを作って、私は午後の事を追加し、私はpm.phpに行くとき、それは私にエラーを与える:PHP switch文のエラー

Fatal error: Switch statements may only contain one default clause in /home/vol10_3/HIDDEN.com/HIDDEN/htdocs/includes/classes/pm.class.php on line 673

コード:

function get_new_messages($uid=NULL,$type='pm') 
    { 
     if(!$uid) 
      $uid = userid(); 
     global $db; 
     switch($type) 
     { 
      case 'pm': 
      default: 
      { 
       $count = $db->count(tbl($this->tbl),"message_id"," message_to LIKE '%#$uid#%' AND message_box='in' AND message_type='pm' AND message_status='unread'"); 

      } 
      break; 

      case 'notification': 
      default: 
      { 
       $count = $db->count(tbl($this->tbl),"message_id"," message_to LIKE '%#$uid#%' AND message_box='in' AND message_type='notification' AND message_status='unread'"); 
      } 
      break; 
     } 

     if($count>0) 
      return $count; 
     else 
      return "0"; 
    } 
} 
+1

エラーの状態と同じです。 http://php.net/manual/en/control-structures.switch.php –

+0

まだ質問が終わっていない場合は、マニュアルを参照してください。エラーメッセージが完全に自己解読されているため、説明的。 – EJoshuaS

答えて

0

あなたドン」実際には大括弧を使用するか、デフォルトのようにします。

<?php 

switch ($type) { 
    case 'pm': 
     // Do something when $type is 'pm' 
     // This can be multiple statements 
     break; 

    case 'notification': 
     // Do something when $type is 'notification' 
     // This can be multiple statements 
     break; 

    default: 
     // Do something else 
     break; 
} 

他のケースが実行されない場合に実行されるコードに対しては、デフォルトを1回だけ追加します。 "case: 'pm':"セクションは、breakステートメントが終了するまでブロックを開始します。 breakステートメントがない場合、次のブロック(この場合は通知)に入ります。

ここに、PHP's websiteへのリンクがあります。これには、これらのステートメントの動作の詳細と詳細がいくつかあります。