mysql - Codeigniter: unable to show result in desc order with count -
i have 2 tables,
instructions ------------- instruction_id int(11) primary key (auto_increment) instruction text user_id int(11) foreign key instrunctionlike ----------------- instrunction_likeid int(11) primary key (auto_increment) instrunction_id int(11) foreign key
in instructions & in instrunctionlike table there many rows, what want , likes
count in desc order instrunctionlike table. eg. select*from instrunctionlike order count(instrunctionlike.instrunction_likeid)...
below tried, confuse how implement count on rows desc order. please me solve issue
//----------------------------------------------------------------------------------- public function fetch_agreed_desc_order_instruction($limit, $start) { $this->load->database(); $this->db->limit($limit, $start); $this->db->join('userdetails', 'userdetails.user_id = instructions.user_id'); $this->db->join('instrunctionlike', 'instrunctionlike.instrunction_id = instructions.instruction_id'); $this->db->order_by('instrunctionlike.instrunction_id', 'desc'); $this->db->group_by("instrunctionlike.instrunction_id"); $query = $this->db->get("instructions"); if ($query->num_rows() > 0) { foreach ($query->result() $row) { $data[] = $row; } return $data; } return false; }
sample output:
instructions likes ............. 78 ............. 66 ............. 56 ............. 34 ............. 12 ............. 1 ............. 1 ............. 0
whlie want group instrunction_id
, don't want order that. instead want order count(instrunction_id)
:
$this->db->order_by('count(instrunctionlike.instrunction_id)', 'desc'); $this->db->group_by("instrunctionlike.instrunction_id");
Comments
Post a Comment