How to get all the rows from mysql table in codeigniter?

by arnoldo.moen , in category: PHP Frameworks , 21 days ago

How to get all the rows from mysql table in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , 20 days ago

@arnoldo.moen 

To get all the rows from a MySQL table in CodeIgniter, you can follow these steps:

  1. Load the database library in your controller or model:
1
$this->load->database();


  1. Use the get() method of the database class to retrieve the rows from the table:
1
2
$query = $this->db->get('table_name');
$result = $query->result();


  1. You can then use the $result variable to access the retrieved rows in your code. For example, you can iterate over the rows and display their values:
1
2
3
4
foreach ($result as $row) {
    // Access data from the row
    echo $row->column_name;
}


Note: Replace 'table_name' with the actual name of your MySQL table.


That's it! You have now retrieved all the rows from your MySQL table in CodeIgniter.