简体   繁体   中英

How to sort records by date?

I need help in sorting my records by date descending or ascending as long as it is sorted. I search google how to sort it and found some codes but don't know where to put it in my current code..

  <div id="bgbp"></div>
   <div id="navi">
      <?php 
        echo anchor('site/booking_page',"New Booking");
        echo anchor('site/view', "Records");
        echo anchor('site/view_inquiries', "Inquiries");
 ?>
   </div>

  <div id="vi">
   <div id = "search_field">
<?php 
    $search_field = array('name'=>"search_field",'placeholder'=>"Search booking : Type the name of guest.");
    echo form_open('site/view');
    echo form_input($search_field);
    echo form_submit('search',"Search");
 ?>

       <?php 
          $this->table->set_heading("Name","Nationality","Contact Number","Number of Guest","Date of Arrival","Package","Other Request","Delete Record","Edit Record");
          $qry = $this->db->like('name',$search_key)->get('booking');
          if ($qry->num_rows > 0) {
           foreach ($qry->result() as $row) {
$this->table->add_row(anchor('site/print_records/'.$row->id, $row->name, 'target="_blank"'),$row->nationality,$row->contactnum,$row->number_of_guest,$row->date,$row->package,$row->request,anchor('site/delete/'.$row->id, 'Delete'),anchor('site/update/'.$row->id, 'Edit'));
    }
    }
      else{
      echo "No records found!";
     }

       echo $this->table->generate();

        ?>

If my wild guess is correct, you are using something like Active Record , which should provide you with an order_by method.

Something like this should therefore do the trick:

$this->db->like('name', $search_key)->order_by('bla')->get('booking');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM