[英]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.. 我在Google中搜索了如何对它进行排序,并找到了一些代码,但不知道将其放在我当前的代码中。
<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. 如果我的猜测正确,那么您正在使用Active Record之类的东西,它应该为您提供一个order_by
方法。
Something like this should therefore do the trick: 这样的事情应该可以解决这个问题:
$this->db->like('name', $search_key)->order_by('bla')->get('booking');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.