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;
}
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);