dongli9894 2012-09-25 08:23
浏览 7

如果构造只显示else值 - PHP

Here is my statement:

if($row_x['xfield']==$_POST['x1'] AND $row_x['yfield']==$_POST['y'])
{
   echo "ok";
}
else {
   echo "invalid";
}

When both are not equal to each other, it must display 'invalid' else, 'ok'. But in this case it displays 'invalid' whether it is valid or not.

Any clues to why?

  • 写回答

4条回答 默认 最新

  • donglu6303 2012-09-25 08:28
    关注

    You said 'when BOTH are NOT equal'... implying you would want to use '!=' instead of '==' in your comparisons. See this T/F chart for &&:

    --------------
    | X | && | Y |
    --------------
    | F | F  | F |
    --------------
    | F | F  | T |
    --------------
    | T | F  | F |
    --------------
    | T | T  | T |
    --------------
    

    The X statement must be true AND the Y statement must be true. In your example

    $row_x['xfield']==$_POST['x1']
    

    must be TRUE as well as

    $row_x['yfield']==$_POST['y']
    

    But if I read your question you will want to have both statements as FALSE to show 'invalid'. So you'll need to substitute '==' for '!=' in each statement.

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序