CodeIgniter Forums
or_group_start Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: or_group_start Problem (/showthread.php?tid=67470)



or_group_start Problem - mertdogan - 02-25-2017

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.


RE: or_group_start Problem - Wouter60 - 02-25-2017

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.


RE: or_group_start Problem - mertdogan - 02-25-2017

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