我有一个问题,我的订单在codeigniter [英] I am having an issue with my order by in codeigniter

查看:77
本文介绍了我有一个问题,我的订单在codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,当我通过Date_Scheduled desc订单时,它仍然先离开最早的日期。我试图得到它,使最新的日期显示第一和最早的日期最后。不确定是我正确写这个。

For some reason when I do order by Date_Scheduled desc it is still leaving the oldest date first. I am trying to get it so that the newest date shows first and oldest date last. Not sure is I am writing this correctly.

这是我的模型,它是get employee函数。

Here is my model it is the get employee function.

<?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

This answer solves part of your problem, because you should handle dates with the correct column type date and not varchar.

如果查询结果总是返回 ORDER BY ASC ,则可以翻转数组。 p>

If the result of your query always returns ORDER BY ASC, you can flip the array.

array_reverse($this->Employee_model->get_employee());

这篇关于我有一个问题,我的订单在codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆