简体   繁体   中英

WHERE clause in mysql php

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 ?!?

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)...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM