CodeIgniter Forums
ActiveRecord like_in - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: ActiveRecord like_in (/showthread.php?tid=40149)



ActiveRecord like_in - El Forum - 03-31-2011

[eluser]maf_9000[/eluser]
i want to search in db with an array
Code:
$this->db->where_in('tags', $tags);
is giving me the exact result not matching
and
Code:
$this->db->like('tags', $tags);
doesn't take arrays (or it dose ?)

any help please


ActiveRecord like_in - El Forum - 03-31-2011

[eluser]InsiteFX[/eluser]
where_in does not take an array!

But you could use like which does take an Associative array.

InsiteFX


ActiveRecord like_in - El Forum - 03-31-2011

[eluser]maf_9000[/eluser]
thanks Mr InsiteFX
i need to search in tags column in db with any element of the array $tags i have created
what is the syntax please


ActiveRecord like_in - El Forum - 03-31-2011

[eluser]danmontgomery[/eluser]
[quote author="InsiteFX" date="1301595456"]where_in does not take an array!

But you could use like which does take an Associative array.

InsiteFX[/quote]

where_in only takes arrays...

Code:
$this->db->where_in('some_field', array(1,2,3,4));


[quote author="maf_9000" date="1301596961"]thanks Mr InsiteFX
i need to search in tags column in db with any element of the array $tags i have created
what is the syntax please[/quote]

There's no "like in" functionality in MySQL, you would have to use or_like, or manually construct a where() string.

Code:
$this->db->or_like('field', 'value_a');
$this->db->or_like('field', 'value_b');

// or

$this->db->where('(`field` LIKE "%value_a%" OR `field` LIKE "%value_b%")', NULL, FALSE);



ActiveRecord like_in - El Forum - 03-31-2011

[eluser]InsiteFX[/eluser]
@noctrum, Thanks I must have read it wrong! Plus I think I am spending to much time on here LOL!

InsiteFX


ActiveRecord like_in - El Forum - 03-31-2011

[eluser]maf_9000[/eluser]
thanks noctrum
i have used the following code
Code:
foreach ($tags as $tag){
            $this->db->or_like('tags', urldecode($tag));
        }