首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构造if,if else,else语句

构造if,if else,else语句
EN

Stack Overflow用户
提问于 2010-05-02 04:12:05
回答 2查看 365关注 0票数 0
代码语言:javascript
复制
/* 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))
    {
        $database->addLeagueTable();
        $_SESSION['players'] == $subplayers;
        $comp_name == '$format_$game_$name_$season';
        $_SESSION['comp_name'] == $comp_name;
        return 0;  //New user added succesfully
    }
    else
    {
        return 2;  //Registration attempt failed
    }

目前,它没有做任何这些事情:

代码语言:javascript
复制
$database->addLeagueTable();
    $_SESSION['players'] == $subplayers;
    $comp_name == '$format_$game_$name_$season';
    $_SESSION['comp_name'] == $comp_name;

有没有更好的方法来做这件事?

编辑中!

代码语言:javascript
复制
$comp_name = "$subformat_$subgame_$subname_$subseason";
        $_SESSION['comp_name'] = $comp_name;

这段代码只在$subseason中生成什么?这有什么显而易见的原因吗?

进一步编辑!

代码语言:javascript
复制
else if($database->addLeagueInformation($subname, $subformat, $subgame, $subseason, $subwindow, $subadmin, $subchampion, $subtype))
    {
        $_SESSION['players'] = $subplayers;
        $comp_name = "$subformat_$subgame_$subname_$subseason";
        $_SESSION['comp_name'] = $comp_name;
        $database->addLeagueTable();
        return 0;  //New user added succesfully
    }

和函数addLeagueTable()

代码语言:javascript
复制
function addLeagueTable() {
   $q = "CREATE TABLE `$_SESSION[comp_name]` (
     `user` VARCHAR( 30 ) NOT NULL ,
        `team` VARCHAR( 40 ) NOT NULL ,
        `home_games_played` INT( 3 ) NULL DEFAULT '0',
        `home_wins` INT( 3 ) NULL DEFAULT '0',
        `home_draws` INT( 3 ) NULL DEFAULT '0',
        `home_losses` INT( 3 ) NULL DEFAULT '0',
        `home_points` INT( 3 ) NULL DEFAULT '0',
        `home_goals_for` INT( 3 ) NULL DEFAULT '0',
        `home_goals_against` INT( 3 ) NULL DEFAULT '0',
        `away_games_played` INT( 3 ) NULL DEFAULT '0',
        `away_wins` INT( 3 ) NULL DEFAULT '0',
        `away_draws` INT( 3 ) NULL DEFAULT '0',
        `away_losses` INT( 3 ) NULL DEFAULT '0',
        `away_points` INT( 3 ) NULL DEFAULT '0',
        `away_goals_for` INT( 3 ) NULL DEFAULT '0',
        `away_goals_against` INT( 3 )  NULL DEFAULT '0'
        )";
   return mysql_query($q, $this->connection);
}

有什么想法吗?

我是如何通过的..。

代码语言:javascript
复制
      $retval = $session->createLeague($_POST['name'], $_POST['players'], $_POST['format'], $_POST['game'], $_POST['season'], $_POST['window'], $_POST['admin'], $_POST['champion'], $_POST['type']);

这会将它们发送到addLeagueInformation被发送到的函数!

EN

回答 2

Stack Overflow用户

发布于 2010-05-02 04:17:22

==是一个比较运算符,但例如在$_SESSION['players'] == $subplayers;中,您需要赋值运算符=

也许你对$comp_name == '$format_$game_$name_$season';也有意见。在单引号的字符串中,php不会替换变量。

票数 5
EN

Stack Overflow用户

发布于 2010-05-02 04:18:12

有没有更好的方法来做到这一点?

实际执行任务吗?

代码语言:javascript
复制
$_SESSION['players'] = $subplayers;
// ------------------^ one '=' instead of two '==' (which is for comparison).
$comp_name = "{$format}_{$game}_{$name}_{$season}";
// double quotes to allow substitution,
// {...} to avoid interpreting the variable name as `$format_`.
$_SESSION['comp_name'] = $comp_name;

如果您希望它们被执行,请确保addLeagueInformation在您的测试中真正返回一个非False值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2751394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档