doumao1917 2014-12-11 08:59
浏览 16
已采纳

复杂的`if`case,对吗?

I'm trying really hard to figure out how to solve this problem. Please be gentle, i'm still learning!

There are four workplaces named: B.Avf, R.Avf, Office and Production. Products is passing theese workplaces. Now i'm building a script that can alert if the same product is passing the same workplace twice. Now, this is the hard part: If the product has passed "B.Avf" it can't pass "R.Avf" whitout an alert, same if the product has passed "R.Avf" it can't pass "B.Avf" whitout and alert. But if the product has passed for ex. "R.Avf" it´s ok to pass "Office" whitout an alert.

This is what i got so far: (It's like example number 5 =)

Maby should i create nested ifstatements instead?

This code will turn true all times!

PHP

if($_SESSION['user']['usr_workplace'] == "R.Avf" ||
   $_SESSION['user']['usr_workplace'] == "B.Avf" && 
   strpos($history, "R.Avf") !== FALSE ||
   strpos($history, "B.Avf") !== FALSE)
  • 写回答

5条回答 默认 最新

  • dongqian3750 2014-12-11 09:04
    关注

    Your if condition should be :

    //IF this session user workplace is "B.Avf" or "R.Avf"
    //AND "B.Avf" or "R.Avf" excist in history, then alert!
    
    if(($_SESSION['user']['usr_workplace'] == "R.Avf"  || $_SESSION['user']['usr_workplace'] == "B.Avf") && (strpos($history, "R.Avf") !== FALSE || strpos($history, "B.Avf") !== FALSE))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏