How to add only some columns from query in codeigniter?

by lindsey.homenick , in category: PHP Frameworks , 10 months ago

How to add only some columns from query in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 10 months ago

@lindsey.homenick 

To add only some columns from a query in CodeIgniter, you can use the select() method of the database library.


Here's an example:

1
2
$this->db->select('column1, column2, column3');
$query = $this->db->get('table_name');


In the select() method, you can specify the columns you want to fetch from the query result. Separate the column names with commas.


After calling select(), you can use the get() method to execute the query and obtain the result. In the example above, table_name is the name of the table you want to retrieve the columns from.


This will fetch only the specified columns from the query result.