我有兩個表遞減順序,笨:無法顯示的結果與數
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
在說明&在instrunctionlike表有很多行, 我想要的是,獲得likes
計數從類似instrunction的表中順序排列。 eg. select*from instrunctionlike order by count(instrunctionlike.instrunction_likeid)...
下面是我嘗試過,但我很困惑如何實現與desc順序的行計數。 請幫我解決這個問題
//-----------------------------------------------------------------------------------
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() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
輸出示例:
instructions Likes
............. 78
............. 66
............. 56
............. 34
............. 12
............. 1
............. 1
............. 0
Actully,從我瞭解的問題,你希望用戶的列表,他喜歡以降序計數。對? – Rajnish
@Rajnish是的,你是對的。 –
請張貼一些樣本數據和期望的輸出 –