【发布时间】:2018-01-03 22:22:14
【问题描述】:
我构建了一个程序,发现 2018 年的排序不正确。我修复了它,所以它会首先显示 2018,但它仍然有一个正确排序的问题,现在它显示示例 1/02/2018 然后 1/03/218 等等,但我需要它显示 1/03/2018 然后 1 /2/2018 然后是整个 2017 年。这是我的模型部分代码,如果需要更多代码,我将添加它。
模型.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class visitor_log_model extends CI_Model {
var $table = 'visitor_log_list';
var $column = array('date','name','vendor','department','contact_person','expected_arrival_time'); //set column field database for order and search
var $order = array('id' => 'desc'); // default order
public function __construct()
{
parent::__construct();
$this->load->database();
}
//gets the gets all the records from the database
private function _get_datatables_query()
{
$this->db->from($this->table);
$this->db->order_by("date", "asc");
$this->db->order_by("expected_arrival_time", "asc");
$i = 0;
foreach ($this->column as $item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$column[$i] = $item; // set column array variable to order processing
$i++;
}
【问题讨论】:
-
那些“日期”列真的是日期类型吗?如果不是,他们应该是;你会免费得到这个。
-
它是一个带有codeigniter的微软sql server
-
我只是检查了它设置为 navchar 的数据库,因为我使用的是日期选择器,所以是否需要更改日期是否重要
标签: php sql-server codeigniter