1

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

3
  • It'd probably help to see the source of the check_fail() function. Commented May 1, 2012 at 8:33
  • is task_id really a string? if you debug some rendered sql statements, and execute them directly in a sql browser (like phpmyadmin), do you get results there? Commented May 1, 2012 at 8:55
  • check fail , is the first statmenet Commented May 1, 2012 at 9:30

1 Answer 1

1
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)...
Sign up to request clarification or add additional context in comments.

1 Comment

I fixed it..there is no error...But why does it return results..see update

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.