codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

not able to set OR condition for query.

Open tejashsoni111 opened this issue 10 years ago • 7 comments

Is it possible to set OR condition for any query?

I need to set condition for following query : select * from users where username='abc' or email='[email protected]';

tejashsoni111 avatar Jan 06 '16 14:01 tejashsoni111

you could use active record or_where(); On Jan 6, 2016 5:02 PM, "tejashsoni111" [email protected] wrote:

Is it possible to set OR condition for any query?

I need to set condition for following query : select * from users where username='abc' or email='abc@defcom';

— Reply to this email directly or view it on GitHub https://github.com/jamierumbelow/codeigniter-base-model/issues/216.

dawondyifraw avatar Jan 06 '16 18:01 dawondyifraw

@dadenewyyt , how to use or_where(); with get_by() or get_many() methods? Do I need to add new method for it?

tejashsoni111 avatar Jan 07 '16 05:01 tejashsoni111

I guess u need to።modify the actual code።base on. MYmodel.php other wise ur have the option to define a method inside ur model like student_model.php a function።purly apply codei።tired active record the or_where query please sear h on that. On Jan 7, 2016 8:06 AM, "tejashsoni111" [email protected] wrote:

@dadenewyyt https://github.com/dadenewyyt , how to use or_where(); with get_by() or get_many() methods? Do I need to add new method for it?

— Reply to this email directly or view it on GitHub https://github.com/jamierumbelow/codeigniter-base-model/issues/216#issuecomment-169552462 .

dawondyifraw avatar Jan 07 '16 09:01 dawondyifraw

Can we use get_by() on email and if the returns null again make a get_by() on username?

Is this technique costly and inefficient considering the database has huge number of rows?

gautamsawala avatar Jan 11 '16 21:01 gautamsawala

@gautamsawala, I think you can do that by executing two different QUERIES or by using or_where().

vsogrimen avatar Jan 12 '16 00:01 vsogrimen

@vsogrimen do we have 'or_where()' as in built function in MY_Model? I cannot find it!

gautamsawala avatar Jan 19 '16 16:01 gautamsawala

You can use this form:

$this->users->get_many_by("collumn1 = 1 OR collumn1 = 2 OR collumn1 = 3");

this works for me!

davidvrsantos avatar Jul 26 '16 13:07 davidvrsantos