Php 我在codeigniter中的订单有问题
由于某些原因,当我按日期进行订购时,它仍然会先保留最早的日期。我正试图得到它,以便最新的日期显示第一和最早的日期最后。我不确定我写的是否正确 这是我的模型,它是get employee函数Php 我在codeigniter中的订单有问题,php,sql-server,codeigniter,Php,Sql Server,Codeigniter,由于某些原因,当我按日期进行订购时,它仍然会先保留最早的日期。我正试图得到它,以便最新的日期显示第一和最早的日期最后。我不确定我写的是否正确 这是我的模型,它是get employee函数 <?php class Employee_model extends CI_Model { public function insert_employee($data) { $this->db->insert('employee_list',$data); r
<?php
class Employee_model extends CI_Model
{
public function insert_employee($data)
{
$this->db->insert('employee_list',$data);
return $this->db->insert_id();
}
public function get_employee()
{
$this->db->select('*');
$this->db->from('employee_list');
$this->db->where('status',1);
$this->db->order_by ("Date_Scheduled", "desc");
$this->db->order_by("Scheduled_Area", "desc");
$this->db->order_by("Time_Reported", "desc");
$query =$this->db->get();
return $query->result();
}
public function delete_employee($id,$data)
{
$this->db->where('id',$id);
$this->db->update('employee_list',$data);
return print_r($data);
}
public function edit_employee($id)
{
$this->db->select('*');
$this->db->from('employee_list');
$this->db->where('id',$id);
$this->db->where('status',1);
$query =$this->db->get();
return $query->result();
}
public function update_employee($data,$id)
{
$this->db->where('id',$id);
$this->db->update('employee_list',$data);
return print_r($data);
}
}
这个答案解决了部分问题,因为您应该使用正确的列类型date
来处理日期,而不是varchar
如果查询结果始终返回ASC的顺序,则可以翻转数组
array_reverse($this->Employee_model->get_employee());
这是一个延伸,但计划日期的数据类型是什么?它是navchar(50)这就是问题所在吗?我需要在字段中回显日期,以便用户能够更改日期如果我让系统输入日期,它将不允许更改您所说的系统不允许更改是什么意思?我将把它放在我的模型或控制器中的什么位置?这是我的conrtoller now$data['employee']=$this->employee_model->get_employee();我试过没用我想我会把我的nvarchar 50改成date改成date也没用还是最老的date First你不应该使用我在你的模型中告诉你的代码。您应该在控制器上使用它<代码>$data['employee']=array\u reverse($this->employee\u model->get\u employee())代码>