How to get field names of table in Codeigniter
Created at 24-May-2021 ,
By samar
How to get field names of table in Codeigniter
In this tutorial, we will try to find the solution to "How to get field names of table in Codeigniter" through programming.
You can get field (column) names of a table in Codeigniter using the getFieldNames() method which is used in Codeigniter 4. This method returns all the column names of the specified table in array form. You can also use the list_fields() method on the $this->db object to get the list of all columns of the table in codeigniter 3.-
Get column names of table in codeigniter 4
--PATH app\Controllers\<Home>.phppublic function getColumnNamesFromTable(){ $db = \Config\Database::connect(); $fields = $db->getFieldNames('heroes'); foreach ($fields as $field) { echo $field . "<br>"; } die(); }
-
Get column names of table in Codeigniter 3
$fields = $this->db->list_fields('heroes'); foreach ($fields as $field) { echo $field . "<br/>"; }
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: CodeIgniter
- How to move from one view to another in Codeigniter
- Update an existing table record with +1 in CodeIgniter
- Convert dd/mm/yyyy to yyyy-mm-dd in codeigniter
- How to select all checkbox in Codeigniter
- Get last executed query in codeigniter
- How to load a view in CodeIgniter?
- Codeigniter 4 call model function from controller
- Default htaccess file code Codeigniter
- No input file specified Codeigniter
- Call to undefined function CodeIgniter\locale_set_default()
- Get the version codeIgniter
- How to create custom helper in codeigniter 4
- Unable to set session in codeigniter
- How to call helper function in Codeigniter view