return only one column data from table in codeigniter

To return only one column data from a table in CodeIgniter, you can follow these steps:

Step 1: Load the CodeIgniter database library by adding the following code in your controller or model file:

$this->load->database();

Step 2: Use the select() method to specify the column you want to retrieve. You can do this by adding the column name as an argument to the select() method. For example, if you want to retrieve the name column from a table called users, you can use the following code:

$this->db->select('name');

Step 3: Specify the table from which you want to retrieve the data using the from() method. For example, if the table name is users, you can use the following code:

$this->db->from('users');

Step 4: Execute the query and retrieve the result using the get() method. This will return a query result object that you can use to access the data. For example:

$query = $this->db->get();

Step 5: Extract the data from the query result object. You can use the result() method to get the data as an array of objects, where each object represents a row in the table. For example:

$data = $query->result();

Step 6: Finally, you can use a loop to access the values of the column you retrieved. For example, if you want to access the name column, you can use the following code:

foreach ($data as $row) {
    echo $row->name;
}

This will echo the value of the name column for each row in the table.

That's it! Following these steps will allow you to retrieve only one column data from a table in CodeIgniter.