Welcome Guest, Not a member yet? Register   Sign In
simple problem with table library
#1

[eluser]ralf0909[/eluser]
i have a problem with table library, i want to show the table with all the data of the user table but something is wrong with me:

this is the model:
Code:
class User_model extends CI_Model {
    
        function get_users()
        {          
           $query = $this->db->get('user');
           return $query->result();              
        }
}

this is the controller:
Code:
class Users extends CI_Controller {
    
        function index()
        {            
            $data = array();    
            $this->load->library('table');
            $this->load->model('user_model');
                    
            if( $query = $this->user_model->get_users() )
            {
                $data['users'] = $query;            
            }
            
            $this->load->view('user_view', $data);
        }

and
Code:
<?php echo $this->table->generate($data); ?>
inside the view, it doesn't work, what's the error???


the only way to get table work is to put this inside the controller:
Code:
$this->load->library('table');

$query = $this->db->query("SELECT * FROM user");

echo $this->table->generate($query);

but then i can't move the table where i want on the page
#2

[eluser]osci[/eluser]
try
Code:
$data['table']=$this->table->generate($query);

you could use your model though if you modified the return
Code:
return $query;

and do
Code:
$data['table']=$this->table->generate($this->user_model->get_users());

and use $table in your view
#3

[eluser]ralf0909[/eluser]
thank you, now the code works Smile




Theme © iAndrew 2016 - Forum software by © MyBB