Jump to content


Taking where_in function () in codeigniter to GC

where_in where in_where

  • Please log in to reply
2 replies to this topic

#1 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguĂ­n, Cuba

Posted 19 June 2013 - 03: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 :)

 

 

 



#2 Gursharan Singh

Gursharan Singh

    Newbie

  • Members
  • Pip
  • 1 posts

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



#3 Carlos Alvarez F

Carlos Alvarez F

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 28 March 2016 - 05: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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users