dongxuxian1123 2018-01-09 12:52
浏览 61
已采纳

PHP - 在带有函数的IF语句中使用OR

I am using OR in if statement While adding OR its not working. Follow the code :

if(!exists('vouchers','v_id',$generate_id) OR !exists('vouchers','hash',$generate_hash))
{
     //Doing something
}

But when I do only one function call its workes.

if(!exists('vouchers','v_id',$generate_id)){//WORK...}

exists function :

function exists($table,$where,$value){
global $db;
$query = $db->query('SELECT * FROM '.$table.' WHERE '.$where.'='.$value.'');
if($query->num_rows == 0) {
    return false;
}else{
    return true;
}

}

Any helps to fix my code ?

  • 写回答

1条回答 默认 最新

  • doushi2047 2018-01-09 12:54
    关注

    You need to use the logical AND operator if you want to check the both like :

    if(!exists('vouchers','v_id',$generate_id) AND !exists('vouchers','hash',$generate_hash)){
    ___________________________________________^^^
    

    Else using the OR operator, the code inside condition will be reached if just one of the condition is true.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?