⚠ 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

Full Search



corn

corn
  • profile picture
  • Member

Posted 04 November 2015 - 16:49 PM

Hi!

 
If i use $crud->where(statement) command and full search with a string, then i can get full result back. 
Search by one field is fine.
 
is this a bug?

 


tamako

tamako
  • profile picture
  • Member

Posted 23 November 2015 - 13:20 PM

I have same problem. 

 
I have two tables: cities and coutries.
 
CREATE TABLE IF NOT EXISTS `cities` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `country_id` int(10) not null,
   `city` varchar(255) NOT NULL,
   `active` int(1) not null,
  PRIMARY KEY (`id`),
  FOREIGN KEY (country_id) REFERENCES countries (id)
) ENGINE=MyISAM;
 
CREATE TABLE IF NOT EXISTS `countries` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `country` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM;
 
My controller is:
 
    public function cities() {
        
        $crud = new grocery_CRUD();
        $crud->set_theme('flexigrid');
        $crud->set_table('cities');
        $crud->where('active', 1);
        $crud->set_relation('country_id', 'countries', 'country');
        $output = $crud->render();
        $this->_example_output($output);
    }
    
      public function countries() {
        
        $crud = new grocery_CRUD();
        $crud->set_theme('flexigrid');
        $crud->set_table('countries');
        $output = $crud->render();
        $this->_example_output($output);
    }
    
If i try to search for the word "Tor" i would expect to see 1 rows but i will get all the rows! why?
grocery.jpg
my select is:
SELECT `cities`.*, j93bfec8a.country AS s93bfec8a
FROM `cities`
LEFT JOIN `countries` as `j93bfec8a` ON `j93bfec8a`.`id` = `cities`.`country_id`
WHERE `active` =0
OR  `j93bfec8a`.`country` LIKE '%Tor%' ESCAPE '!'
OR  `city` LIKE '%Tor%' ESCAPE '!'
OR  `active` LIKE '%Tor%' ESCAPE '!'
HAVING `active` =0
 LIMIT 5
 
Someone to help me please!
 
I use grocerycrud v1.5.2 and codeigniter v3.0.3.

tamako

tamako
  • profile picture
  • Member

Posted 27 November 2015 - 07:41 AM

I had time to debug.


i search for 'city', then sql is:
SELECT `cities`.*, j93bfec8a.country AS s93bfec8a
FROM `cities`
LEFT JOIN `countries` as `j93bfec8a` ON `j93bfec8a`.`id` = `cities`.`country_id`
WHERE `cities`.`active` =0
AND  `city` LIKE '%Tor%' ESCAPE '!'
 LIMIT 5
 
This correct! Because "and" is in sql "`cities`.`active` =0
AND  `city` LIKE '%Tor%' ESCAPE '!'" 
 
But previous sql is (Search all):
SELECT `cities`.*, j93bfec8a.country AS s93bfec8a
FROM `cities`
LEFT JOIN `countries` as `j93bfec8a` ON `j93bfec8a`.`id` = `cities`.`country_id`
WHERE `active` =0
OR  `j93bfec8a`.`country` LIKE '%Tor%' ESCAPE '!'
OR  `city` LIKE '%Tor%' ESCAPE '!'
OR  `active` LIKE '%Tor%' ESCAPE '!'
HAVING `active` =0
 LIMIT 5
 
"And" will be "or" in this:  
"`active` =0 OR  `j93bfec8a`.`country` LIKE '%Tor%' ESCAPE '!'"
 
therefore returns all rows.
 
bug? someone?