douye9822 2012-05-01 07:51
浏览 56

mysql php中的WHERE子句

This is mysql statement

 $query="SELECT * FROM `error_report` AS e
                 INNER JOIN `pages` AS p ON e.page_id=p.page_id
                WHERE `task_id` ='".$this->task_id."' AND 
                    ((google_host_fail=1
                    OR robots_noindex_nofollow=1
                    OR xrobots_noindex_nofollow=1
                    OR google_cache_fail=1
                    OR forbidden_word=1)
                    OR (google_title_fail=1 AND h1_fail=1 AND h2_fail=1 AND h3_fail=1))";

I want here, to return results on condition that there is task id.. and or any of the two satements enclosed in brackets The problem is in the last where statement, I want a condition that if all those fields.

I have got another sql problem with a similar statement.

     public function check_success()
  {
      $query="SELECT e.* FROM `error_report` AS e
           INNER JOIN `pages` AS p ON e.page_id=p.page_id
            WHERE `task_id` ='".$this->task_id."' 
                AND ((google_title_fail=0) OR (google_title_fail=1 AND h1_fail=0))";
      $result=$this->db->query($query)->result_array();
      if(count($result)>0)
      {
          return 1;
      }
     return 0;
  }

I want to achieve the same above.. But I dont see that my statements work

How can I enclose the where statements with brackets so that they will work in both functions..

   public function findFinalResult()
  {
      if($this->check_fail())
      {
          return "Failure";
      }
     else if($this->check_success())
     {
         return "Success";
     }
     return "Warning";

  }

Final results gives fail each time..? why ?!?

  • 写回答

1条回答 默认 最新

  • duanqun9740 2012-05-01 08:11
    关注
    SELECT * FROM error_report AS e INNER JOIN pages AS p ON e.page_id=p.page_id WHERE task_id ='151' AND (OR google_host_fail=1 OR robots_noindex_nofollow=1 OR xrobots_noindex_nofollow=1 OR google_cache_fail=1 OR forbidden_word=1) OR (google_title_fail=1 AND h1_fail=1 AND h2_fail=1 AND h3_fail=1)
    

    The error occurs due the unecessary OR statement at the beginning of the brackets.

    ...AND (OR google_host_fail=1 OR robots_noindex_nofollow=1
    OR xrobots_noindex_nofollow=1 OR google_cache_fail=1 OR forbidden_word=1)...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染