CodeIgniter Forums
i have a problem with $this->db->like - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: i have a problem with $this->db->like (/showthread.php?tid=21644)



i have a problem with $this->db->like - El Forum - 08-16-2009

[eluser]minhbu[/eluser]
i want to search 1 number in db with column is string
example
i have string id_news= "1,2,3,4,5,6,11,12,14,19"
when i use $this->db->like("id_news",1)
result is 1,11,12,14,19 but i want to result is 1
Please help me.


i have a problem with $this->db->like - El Forum - 08-16-2009

[eluser]Dam1an[/eluser]
Assuming the numbers will always be in order, you could do something like
Code:
$this->db->query("SELECT * FROM `news` WHERE `id_news` = '1' OR `id_news` LIKE '1,%'");

The first one will catch just 1 on its own, and the second part will get any strings starting off with the number 1 and any number of numbers following


i have a problem with $this->db->like - El Forum - 08-16-2009

[eluser]minhbu[/eluser]
$this->db->query("SELECT * FROM `news` WHERE `id_news` = '1' OR `id_news` LIKE '1,%'");
if i have a string id_news="11,3,57,6,7,12,1"
i think i try use "select * from news where 1 in(id_news)"