How to use find_in_set() query in codeigniter?

Member

by orpha , in category: PHP Frameworks , 8 months ago

How to use find_in_set() query in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , 8 months ago

@orpha 

To use the find_in_set() query in CodeIgniter, you can use the following code snippet:

1
2
3
4
5
$this->db->select('*');
$this->db->where("FIND_IN_SET('value', column_name) >", 0);
$query = $this->db->get('table_name');

$result = $query->result();


In the above code, 'value' is the value you want to search for in the 'column_name' column of the 'table_name' table. The FIND_IN_SET() function returns the position of the value in the comma-separated list of values in the column. If the value is found, the position will be greater than 0, so we are checking if the position is greater than 0. The result of the query is then stored in the $result variable.


You can customize this code to fit your specific requirements by changing the value, column_name, and table_name accordingly.