[eluser]InsiteFX[/eluser]
Hi R_Nelson
First you wil need a MY_Controller makes it easier to use the the Table Class!
MY_Controller - application/core/MY_Controller
Code:
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('table');
$tmpl = array (
'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
'thead_open' => '<thead>',
'thead_close' => '</thead>',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',
'tbody_open' => '<tbody>',
'tbody_close' => '</tbody>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr class="alt">',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
}
}
Controller extended for the above MY_Controller
Code:
public function index()
{
// Setting headings for the table
$this->table->set_heading('ID', 'Song', ,'Artisit', 'Actions');
// $data will be what you pull from your database table!
foreach ($data as $value => $key)
{
// Build actions links for editing and deleting records! you can do away with this part if your do not need it
$actions = anchor("link_to_edit/edit/".$key['id']."/", "Edit") . anchor("link_to_delete/delete/".$key['id']."/", "Delete");
// Adding a new row to table, remove any $key you do not need.
$this->table->add_row($key['id'], $key['song'], $key['artisit'], $actions);
}
}
View
Code:
<!-- Generate the table in the view. -->
<?php echo $this->table->generate();?>
Note: If you need to redo the table $this->table->clear();
InsiteFX