jignesh
answered Apr 27 '23 00:00
To echo or print a query result at a Controller in CodeIgniter, you can use th e $this->db->get() method to retrieve the results of the query, and then loop through the results using a foreach loop to echo or print the data.
Here's an example of how to echo or print a query result at a Controller in CodeIgniter:
public function my_controller_function() {
$this->db->select('*');
$this->db->from('my_table');
$query = $this->db->get();
foreach ($query->result() as $row) {
echo $row->column1;
echo $row->column2;
// Add additional columns as needed
}
}
In this example, we are selecting all columns from a table named " my_table " and retrieving the results of the query using $query = $this->db->get(). We are then using a foreach loop to loop through the results and echo or print the data for each row.
You can modify the example to suit your specific query needs, changing the table name and column names as necessary. Note that you can also use var_dump () or print_r () instead of echo to print the query results in a more detailed format.