doulian7305 2016-05-26 00:41
浏览 29
已采纳

订单功能在PHP中没有任何作用(CodeIgniter)

I'm using CodeIgniter as a framework. Now I want to order a list but it doesn't react on DESC or ASC.

My code is:

function get_community($limit, $smallicon = false) {
        $this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name');
        $this->db->from('user_to_designment');
        $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id');
        $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id');
        $this->db->group_by('user_id');
        $this->db->order_by('designment_joined', 'desc');
        $this->db->limit($limit);
        $communitys = $this->db->get()->result_array();

        foreach ($communitys as &$community) {
            if($smallicon){
                $community['image'] = self::get_small_user_icon_by_id($community['user_id']);
            }else{
                $community['image'] = self::get_big_user_icon_by_id($community['user_id']);
            }
        }

        return $communitys;
    }
  • 写回答

1条回答 默认 最新

  • donpvtzuux37724 2016-05-26 01:19
    关注

    designment_joined is a count(user_to_designment.user_id) which will give the same value. So you can not see the difference. Try the query directly in PHPMyAdmin and see the result. Also try to change the field name in orderby clause and check.

    eg :

    Replace $this->db->order_by('designment_joined', 'desc'); with $this->db->order_by('user_to_designment.user_id', 'desc'); and check.

    Updated Code:

    $this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name');
            $this->db->from('user_to_designment');
            $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id');
            $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id');
            $this->db->order_by('user_to_designment.user_id', 'desc');
            $this->db->limit($limit);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部