How to display sql table fields in codeigniter?

Member

by adan , in category: PHP Frameworks , a year ago

How to display sql table fields in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 10 months ago

@adan 

To display SQL table fields in CodeIgniter, you can use the following query in your controller method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
public function display_fields() {
    $this->load->database();
    $table_name = 'your_table_name';
    $query = $this->db->query("SHOW COLUMNS FROM $table_name");
    $fields = $query->result_array();
    
    foreach($fields as $field) {
        echo $field['Field'] . "<br>";
    }
}


In this code snippet, we use the SHOW COLUMNS FROM SQL query to retrieve the fields of the specified table "your_table_name". We then loop through the result and display each field name using the echo statement.


Make sure to replace 'your_table_name' with the actual name of your SQL table in the code above.

Related Threads:

How to display a description of a table in oracle sql?
How to display custom product fields on thank you page in woocommerce?
How to display nested lists in a table in vuetify?
How to display text file data in html table?
How to display comma seperated list into table in ember.js?
How to handle sql query in foreach loop in codeigniter?