Without any code from your part, it's just guessing how you initialize the table, but let's assume you've read the CI documentation.
Your controller function could look like this (controller named "Orders.php"):
PHP Code:
public function table($order = 'asc')
{
$data['records'] = $this->orders_model->get_all($order); //get records from model
$data['change_order'] = $order == 'asc' ? 'desc' : 'asc'; //set value for changing the order
//load view to show the table records:
$this->load->view('header');
$this->load->view('orders_table',$data);
$this->load->view('footer');
}
Your model (Orders_model.php):
PHP Code:
public function get_all($order)
{
$query = $this->db->order_by('order_date', $order)->get('orders');
if ($query->num_rows() > 0) {
return $query->result();
}
else {
return NULL;
}
}
Your view (orders_table.php):
PHP Code:
<table>
<thead>
<tr><th>No</th><th>ID</td><th>Data</th><th>Order Date <?= anchor('orders/table/' . $change_order, Change Order);?></th></tr>
</thead>
<tbody>
….
</tbody>
</table>
In this example, you won't see a button, but just a link to change the current order from 'asc' to 'desc'. Hopefully this will give you the idea how it works. Later on, you can change the link into a button.
Good luck!