Jump to content


searching tinyint field (true_false)

search true false tinyint

  • Please log in to reply
2 replies to this topic

#1 fractorr

fractorr

    Member

  • Members
  • PipPip
  • 10 posts

Posted 29 March 2016 - 10:59 PM

I purchased the bootstrap theme and I have a field called active which is a tinyint field with a length of 1 which I use the $crud->field_type('active', 'true_false', array("No", "Yes")); so that it displays Yes / No instead of active / inactive.  This all works great until I try and search on the field, if I enter 1 to search on it works as expected but if I enter 0 to search it does not filter out any records even though there are server records with active set to 0.

 

Anyone come across this and if so any idea how to fix this?

 

 



#2 fractorr

fractorr

    Member

  • Members
  • PipPip
  • 10 posts

Posted 29 March 2016 - 11:24 PM

So this was my fix for this issue, probably not the best way to go about it since it is modifying core code but it seems to work.  I modified the Grocery_crud_model.php file and changed the like function to this.

    function like($field, $match = '', $side = 'both')
    {
    	if ($match == 0) {
		$this->db->where($field, 0);
	} else {
	    	$this->db->like($field, $match, $side);
	}
    }



#3 fractorr

fractorr

    Member

  • Members
  • PipPip
  • 10 posts

Posted 29 March 2016 - 11:44 PM

So I just read up on extending GC, pretty cool.  I created this model and it used the set_model function and it seems to work just fine now and now I am not modifying core code. :)

<?php
class Grocery_crud_model_gdbl  extends Grocery_crud_model  {
    function like($field, $match = '', $side = 'both')
    {
    	if ($match == 0) {
		$this->db->where($field, 0);
	} else {
	    	$this->db->like($field, $match, $side);
	}
    }
}






Also tagged with one or more of these keywords: search, true, false, tinyint

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users