db to table

Derek Jones edited this page Jul 5, 2012 · 14 revisions
Clone this wiki locally

Category:Help::TipsAndTricks Category:Table

Updating my contributions on the wiki has become a nightmare. Please check my svn at google for the latest revisions: http://code.google.com/p/tamer/ CI_TaMeR SVN

I feel we don't have enough sample code so here is one from me on how to get stuff from the database and feed it in to a table:


    function index()
    {
        $query = $this->db->getwhere('Ticket', array('uid' => $this->uid));
        if ($query->num_rows() > 0)
        {
            foreach($query->result_array() as $k => $s):
                $tbresult[$k] = $s;
            endforeach;
            // Remove id fields
            $tbresult = $this->fun->unsetids($tbresult);
            $this->load->library('table');
            foreach($tbresult as $row):
            $v = $row['Ticket No'];
            $row['Ticket No'] = anchor('ticket/view/'.$v,$v);
                $this->table->add_row($row);
            endforeach;            
            $this->table->set_heading(array_keys($row));
            $this->tpl['body'] = $this->table->generate();
            $this->table->clear();

        }

        $this->load->view('layout/blank', $this->tpl);
    }

And this is what it looks like unformatted. You can use css to change the look Image:Screenshot.gif