CodeIgniter Forums
Between Clause in where condition - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Between Clause in where condition (/showthread.php?tid=14069)



Between Clause in where condition - El Forum - 12-17-2008

[eluser]Unknown[/eluser]
Hello,

I m looking for Between clause in db_active_rec, I found nothing for the same, can any one tell me is there anything written in CodeIgniter for range search.

I m looking for a function which will generate following query:

select id, name from emp where id between 100 and 200.


Is there anything for the same?

Lokesh


Between Clause in where condition - El Forum - 12-17-2008

[eluser]MikeHibbert[/eluser]
try:

Code:
$this->db->where("id BETWEEN 100 AND 200");
$this->db->get("mytable");

that should sort it out

Mike


Between Clause in where condition - El Forum - 12-19-2008

[eluser]Unknown[/eluser]
Thanks Mike,

I have this option with me but i m looking for a function like where_in, because as per my framework, i have to generate query at run time.

Lokesh


Between Clause in where condition - El Forum - 12-26-2008

[eluser]darkhouse[/eluser]
I've actually wanted a feature like this, so that I could do something like

Code:
$this->db->where_between('id', 100, 200);

Though I've just done what Mike said to do and never had a problem.

I don't think it's a simple feat to extend the active record class, but what if you made a helper function that was like this:

Code:
function where_between($field, $min, $max){
     $CI = get_instance();
     return $CI->db->where("$field BETWEEN $min AND $max");
}



Between Clause in where condition - El Forum - 12-26-2008

[eluser]MikeHibbert[/eluser]
yeah I agree.

I have written code on more than one occasion to do that sort of thing.

Maybe it something to add.

Mike


Between Clause in where condition - El Forum - 04-27-2011

[eluser]Unknown[/eluser]
You can refer to http://www.cikewang.com/thread-115-1-1.html