2010-05-01 127 views
1

我有以下代碼if語句OOP

/* Errors exist, have user correct them */ 
    if($form->num_errors > 0) 
    { 
    return 1; //Errors with form 
    } 
    /* No errors, add the new account to the */ 
    else if($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype)) 
    { 
     return 0; //New user added succesfully 
    } 
    else 
    { 
    return 2; //Registration attempt failed 
    } 

我想給它添加

$databases->addLeagueTable($name) 

這應該在同一時間發生addLeagueInformation以下。 任何想法?

編輯,這項工作?

else if($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype) 
              && $databases->addLeagueTable($name) && $_SESSION['players'] == $subplayers && $comp_name =  
              "$format_$game_$name_$season" && $_SESSION['comp_name'] = $comp_name) 

回答

1

你應該真的保持與縮進一致,它使代碼更容易閱讀。

總之:

// Errors exist, have user correct them 
if ($form->num_errors > 0) 
{ 
    return 1; // Errors with form 
} 
// No errors, add the new account to the 
else if ($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype) 
    && $databases->addLeagueTable($name)) 
{ 
    return 0; // New user added succesfully 
} 
else 
{ 
    return 2; // Registration attempt failed 
} 
+0

難道我還加&& $ _SESSION [ '玩家'] == $ subplayers ??? – sark9012 2010-05-01 02:55:58

+0

我不認爲這是理想的。如果第一個條件成功(即:addLeagueInformation正確插入數據),但addLeagueTable失敗,則最終的數據不一致。您可能想要在交易中包裝每個交易並評估交易結果,而不是評估兩個單獨的交易。 – 2010-05-01 02:58:00

+0

因此,如果進一步的if語句,去其他地方呢?我已編輯我的問題 – sark9012 2010-05-01 03:02:29