如何按日期对记录进行排序?

时间:2014-03-07 17:44:31

标签: php codeigniter sorting

我需要帮助按日期降序或升序对记录进行排序,只要它已排序。我搜索谷歌如何对它进行排序并找到一些代码,但不知道将它放在我当前的代码中的位置..

  <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();

        ?>

1 个答案:

答案 0 :(得分:1)

如果我的猜测是正确的,您使用Active Record之类的东西,它应该为您提供order_by方法。

这样的事情应该可以解决问题:

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