2017-06-01 39 views
0

這裏搜索到這些值是表我有有逗號seprated價值如何使用數組

+----+----------------------+ 
| id |  title   | 
+----+----------------------+ 
| 1 | math,science,english | 
| 2 | social,hindi   | 
+----+----------------------+ 

列如何搜索欄,如果在我的SQL活動記錄給定數組中的值相匹配的一個

$array=array('math','computer','english'); 

結果應該是

+----+----------------------+ 
| id |  title   | 
+----+----------------------+ 
| 1 | math,science,english | 
+----+----------------------+ 
+0

我明白你的表中有這個權利,你有一個包含逗號分隔值的列。即「數學,科學,英語」,你想搜索「數學」? – hungrykoala

+1

簡單的沒有逗號分隔值的列 – Strawberry

+0

爲什麼有逗號分隔值的表? – WhatsThePoint

回答

0

使用MySQL find_in_set方法,click在這裏查看文檔。

+0

但是在一個值中找到,例如 –

+0

$ this-> db-> where(「FIND_IN_SET('math,computer,english',title)」); –

0

您可以使用FIND_IN_SET()來解決這個問題。

if($array) 
{ 
    $this->db->group_start(); 
     $this->db->where("FIND_IN_SET('$array[0]', title) != ",0); 
     for($x=1; $x < count($array); $x++) 
     { 
     $this->db->or_where("FIND_IN_SET('$array[$x]', title) != ",0); 
     } 
    $this->db->group_end(); 
} 
+0

非常感謝你 –

+0

歡迎。請接受[答案](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),並注意是否有用。 – Shihas

+0

這個答案解決了你的問題嗎? – Shihas

相關問題