⚠ 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

How to use where to select by using array



Mohammed Zayan
  • profile picture
  • Member

Posted 23 June 2012 - 11:51 AM

[size=5]Hi,[/size]
[size=5]I have an array which contain ids and i want to make select where field = any value from the array[/size]
[size=5]

SELECT * FROM `volunteers` WHERE `profileId` IN ($ids)
[/size]
[size=5]where $ids is an array[/size]
[size=5]How can I do that in grocery_CRUD???[/size]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 24 June 2012 - 12:25 PM


$crud->where('profileId IN('.implode(",",$ids).')',null,false);

Marcio Prado
  • profile picture
  • Member

Posted 19 March 2015 - 21:38 PM

Good night,
 
I have a function that returns: $ idsComunidades = Array ([0] => Array ([id] => 0001) [1] => Array ([id] => 0003))
 
I set $ this-> grocery_crud-> where ('idComunidade IN (' implode ("", $ idsComunidades) ')', null, false..);
 
It turns out some errors:
 
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: controllers/home.php
Line Number: 173
 
I thank you

Marcio Prado
  • profile picture
  • Member

Posted 19 March 2015 - 21:40 PM

Follows function:
 
    public function selecionarIDsComunidades($cnpj) {
        $this->db->select('id');
        $this->db->from('tbcomunidades');
        $this->db->where('cnpjOrganizacao', $cnpj);
        $query = $this->db->get();
        
        return $query->result_array('id');
    }