Example code for loading a database in CodeIgniter using PHP

Here is an example that can help you easily find a solution. In your controller file and model file, you can create a table view file in the view folder to fetch your data. Hopefully, this will be helpful to you.
Solution:
CodeIgniter’s latest version (3.0.0) does not support extending its database classes like it does with other libraries. To display the information of the member based on the selected membership, you can refer to login_view.php and result_view.php.
Solution 2:
For more simple examples, you can read the user guide.
Solution:
You can load the database every time you perform a query. In the $load->database(‘localhos or latestdb or sit…’, TRUE) function, the first parameter can be a variable or a function.


Solution 1:

    in controller function 
public function GetAll(){
    $data['all_data'] = $this->Userinsert_model->selectAllData();
    $this->load->view('view_page', $data);
}
in model 
    public function selectAllData() {
        $query = $this->db->get('students');
        return $query->result();
    }
in view 
        
          
            your_table_column_name?>
          
        


Solution 2:


Upon reading your inquiry, I noticed that you did not include the code for retrieving the data. Instead, you only uploaded it into your database.

Here’s an uncomplicated illustration that will help you identify the answer effortlessly.

in your controller file:

public function view()
    {
                $this->load->model('uModel'); //edit it with you model name
                $data['users']= $this->uModel->All();
                $this->load->view('list' , $data);  
    }

in your model file:

//Func for getting all data of a table in a 'users' variable by using get method 
public function All()                   
    {
        return $users = $this->db->get('users')->result_array();
    }

Generate a file in the view folder that contains a table view for retrieving your data.


      
  
        
        
  

Hope it will help you

Frequently Asked Questions

Posted in Php