Welcome Guest, Not a member yet? Register   Sign In
Is there away I can order table data ?
#3

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_orderChange 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!
Reply


Messages In This Thread
RE: Is there away I can order table data ? - by Wouter60 - 10-15-2018, 12:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB