Search in comma separated values in Database
Hello friends, if you want to search in the database for comma separated values, you can easily do this with FIND_IN_SET function.<br />
<br />
Example : Suppose several values like the following are stored in the users additionalgroups field.<br />
1) 1,3,5<br />
2) 4,2,1<br />
3)1<br />
4)6,7<br />
<br />
Now you want to find users who have a value of 1<br />
<br />
You can use this function as follows.<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">...
$query = $db->simple_select("users","uid","FIND_IN_SET('1', `additionalgroups`)>0"
;
...</code></pre>
Hello friends, if you want to search in the database for comma separated values, you can easily do this with FIND_IN_SET function.<br />
<br />
Example : Suppose several values like the following are stored in the users additionalgroups field.<br />
1) 1,3,5<br />
2) 4,2,1<br />
3)1<br />
4)6,7<br />
<br />
Now you want to find users who have a value of 1<br />
<br />
You can use this function as follows.<br />
<pre data-deferred="true" class="block-code line-numbers language-none"><code class="language-none">...
$query = $db->simple_select("users","uid","FIND_IN_SET('1', `additionalgroups`)>0"
...</code></pre>