CodeIgniter Forums
table class help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: table class help (/showthread.php?tid=45389)



table class help - El Forum - 09-19-2011

[eluser]Unknown[/eluser]
I am trying ot use the table class to display a table of data I have retrieved from my database. My model method looks like this:

Code:
function index() {
        $data = array();
        $this->load->library('pagination');
        $this->load->library('table');
        
        $config['base_url'] = 'http://localhost:8888/ci/index.php/site/index';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 5;
        $config['num_links'] = 20;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
        
        $this->pagination->initialize($config);
        
        if($query = $this->site_model->getRecords('data',$config['per_page'],$this->uri->segment(3))) {
            $data['records'] = $query;
        }
        $this->load->view("options_view",$data);
    }

My view (options_view.php) code looks like this:



Code:
if(isset($records)) {
      echo $this->table->generate($records);
   }
   else {
       echo "No Rows Returned!!!";
    }
      
    echo $this->pagination->create_links();


I can use a foreach loop to loop through the $records variable and display the results but would very much like to make use of the awesome table helper class. any ides on where I am going wrong here?

Mike.