dongshenling6585 2016-06-26 00:36
浏览 89

如何根据条件执行if和else块到if语句块?

I have a script like this:

if(isset($_SESSION["LoginValidation"]) && $_SESSION["LoginValidation"] == 1){

    $something = $db->prepare('SELECT cookie FROM users WHERE id = ?');
    $something->execute(array($_SESSION["Id"]));
    $num_row = $something->fetch();
    $_SESSION["cookie"] = $num_row['cookie'];

    if ( $_SESSION["cookie"] != $_COOKIE['login']) ){
        // jump to following else statement (outer else statement)
    }

} else {
    /* here - this block should be execute when
         - That inner if-statement is true
         OR
         - That outer if-statement is false
    */
}

As you see, I need to execute if-statement and if inner if-statement is true then execute else-statement. How can I do that?

  • 写回答

2条回答 默认 最新

  • dongxing2692 2016-06-26 00:41
    关注

    Try something like this:

    $doElse = true;
    if(isset($_SESSION["LoginValidation"]) && $_SESSION["LoginValidation"] == 1){
    
        $doElse = false;
        $something = $db->prepare('SELECT cookie FROM users WHERE id = ?');
        $something->execute(array($_SESSION["Id"]));
        $num_row = $something->fetch();
        $_SESSION["cookie"] = $num_row['cookie'];
    
        if ( $_SESSION["cookie"] != $_COOKIE['login']) ){
            $doElse = true;
        }
        else {
            //rest of the logic
        }
    
    } 
    
    if ($doElse) {
        // here - this block should be execute when inner if-statement is true
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动