Welcome Guest, Not a member yet? Register   Sign In
or_group_start Problem
#1

(This post was last modified: 02-25-2017, 11:42 AM by mertdogan.)

I have a query as
PHP Code:
$this->db->or_group_start()->where('X',$x)->where('Y',$y)->group_end()->where('Z',false)->from('TABLE')->count_all_results() 

and this results

Code:
SELECT COUNT(*) AS "numrows" FROM "TABLE" WHERE ( "X" IS NULL AND "Y" IS NULL ) AND "Z" =0

sql query.

As you can see, where items connected with AND , not with OR.

When i change this code as
PHP Code:
$this->db->or_group_start()->where('X',$x)->or_where('Y',$y)->group_end()->where('Z',false)->from('TABLE')->count_all_results() 

it generates
Code:
SELECT COUNT(*) AS "numrows" FROM "TABLE" WHERE ( "X" IS NULL OR "Y" IS NULL ) AND "Z" =0

as what i want.

If i have to connect where items with this method, what about or_group_start clause? It's name may simlply group_start()

I think this is a bug or wrong method name.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#2

What's the result if you put the query builder elements in this order:
PHP Code:
$this->db
->from('TABLE')
->
where('Z',false)
->
or_group_start()
 
  ->where('X',$x)
 
  ->where('Y',$y)
->
group_end()
->
count_all_results() 
I guess the or_group_start() only has effect if there's a preceding where clause.
Reply
#3

(02-25-2017, 01:35 PM)Wouter60 Wrote: What's the result if you put the query builder elements in this order:
PHP Code:
$this->db
->from('TABLE')
->
where('Z',false)
->
or_group_start()
 
  ->where('X',$x)
 
  ->where('Y',$y)
->
group_end()
->
count_all_results() 
I guess the or_group_start() only has effect if there's a preceding where clause.

Yes you right. It or_group_start connects only if there is a where before it.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB