Jump to content


Gursharan Singh

Member Since 23 Jan 2016
Offline Last Active Feb 23 2016 07:24 AM
-----

#13665 Taking where_in function () in codeigniter to GC

Posted Gursharan Singh on 23 January 2016 - 09:24 AM

@kenshicu

 

I was searching about this functionality and found this post. Your code did not work as expected, but it has helped me a lot to achieve the final result. Your performs a where() operation on each of the values given in the array. 
It is  a clever solution but does not work in every case. In code it was showing SQL errors for the (WHERE 'fieldname' in) clause.

I have done the following simple changes that provides and independent where_in functionality based on the codeigniter's where_in() function. It can also be used in combination with the usual where(), or_where() functions.
 

In the library grocery_crud.php in function protected function get_list()

add:

if(!empty($this->where_in))
               foreach($this->where_in as $where_in):
                $this->basic_model->where_in($where_in[0], $where_in[1]);
               endforeach;

In class grocery_CRUD extends grocery_CRUD_States add:

protected $where_in             = array();

add in the same class, after function public function or_where(..), the following function:

public function where_in($key, $value = NULL, $escape = TRUE)
    {
        if ($value != '()') $this->where_in[] = array($key,$value,$escape);
    }

In Grocery_CRUD_Model.php add the following function after the order_by() function:

function where_in($key, $value = NULL, $escape = TRUE)
    {
        $this->db->where_in( $key, $value, $escape);
    }

in the controller:

$crud->where_in('tablename.EmployeeID', $employee_ids);

where $employee_ids id the same as you suggested, and array of values.

 

 

Thank You, for doing most of the work and pointing me in the right direction.  :)