How to use find_in_set in codeigniter?

Member

by addison , in category: PHP Frameworks , 5 months ago

How to use find_in_set in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 5 months ago

@addison 

In CodeIgniter, you can use the find_in_set function to search for a specific value within a comma-separated list of values. Here's an example of how you can use find_in_set in CodeIgniter:

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

$result = $query->result();


In the above code snippet:

  1. Replace 'table_name' with the name of your table.
  2. Replace 'value_to_search' with the value you want to search for in the column_name field.
  3. Replace 'column_name' with the name of the column that contains the comma-separated list of values.


This code will execute a query to select all rows from the specified table where the column_name field contains the specified value.


You can customize the query further by adding additional conditions using CodeIgniter's Active Record functions.