⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Taking where_in function () in codeigniter to GC



kenshicu
  • profile picture
  • Member

Posted 19 June 2013 - 15:03 PM

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

add:

if(!empty($this->in_where))
   foreach($this->in_where as $in_where):
	$this->basic_model->where($in_where[0].' in '.$in_where[1]);
   endforeach;

In class grocery_CRUD extends grocery_CRUD_States add:

protected $in_where 			= array();

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

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

in the controller:

$crud->in_where('workers.id_workplace', $workplace_list);

where $workplace_list containing for example: (1, 15, 3, 8, 20)

is a list of id of workplaces, to get only the workers who are in the workplace specified in the list.

 

 

if anyone has a better idea, tell me :)

 

 

 


Gursharan Singh
  • profile picture
  • Member

Posted 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.  :)


Carlos Alvarez F
  • profile picture
  • Member

Posted 28 March 2016 - 17:38 PM

Hi, @kenshicu and Gursharan Singh.

Thanks for the info. 

 

I have done the changes that you provides and work as expected, however, the "quickSearchBox" do not work. Well, it works, but not perfectly.  

 

I need your help,

 

I have 1356 registers in my table. And when i use the "where_in" the "quickSearchBox" still displayin the same 1356 registers. But its not true because when i count i have too less. in effect, if i navigate for the pagination from the "quickSearchBox", when i go for the seventh page, do not show me anything.

 

 

error%20busqueda1.jpg

I need help guys! Really, thanks.

PD: excuse my bad English.