How to use find_in_set in codeigniter?

Member

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

How to use find_in_set in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 10 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.

Related Threads:

How to use find_in_set() query in codeigniter?
How to use model function result in controller by codeigniter?
How to use tcpdf in Codeigniter?
How to use where and join in codeigniter?
How to use guzzle on codeigniter?
How to use foreach in codeigniter?