Welcome Guest, Not a member yet? Register   Sign In
Between Clause in where condition
#1

[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
#2

[eluser]MikeHibbert[/eluser]
try:

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

that should sort it out

Mike
#3

[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
#4

[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");
}
#5

[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
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB