所以我想知道这是甚至是最好的方式来管理我的数据表,因为我的查询我没有得到我想要的正确结果。前5名排名问题
我想要它从表中的最后日期条目中获取top5排名。问题是如果character_id为0。当我做我的PHP,看看是否有没有价值,那么它应该TBD呼应,但它仍然没有显示在阵列中它是0。
表:TOP5
id ranking # character_id status_id date_created
1 1 1 1 2011-10-17 17:18:54
2 2 2 1 2011-10-17 17:18:54
3 3 3 1 2011-10-17 17:18:54
4 4 4 1 2011-10-17 17:18:54
5 5 5 1 2011-10-17 17:18:54
6 1 6 1 2011-10-24 12:18:54
7 2 7 1 2011-10-24 12:18:54
8 3 8 1 2011-10-24 12:18:54
9 4 9 1 2011-10-24 12:18:54
10 5 0 1 2011-10-24 12:18:54
function getTop5()
{
$this->db->select('characters.character_name, top5.character_id');
$this->db->from('top5');
$this->db->join('characters', 'characters.id = top5.character_id');
$this->db->where('top5.status_id', '1');
$this->db->order_by('top5.date_created','desc');
$this->db->limit(5);
$query = $this->db->get();
return $query->result_array();
}
Array ([0] =>
Array ([character_name] => \"Mr. Magnificent\" Matt Sharp
[character_id] => 9)
[1] =>
Array ([character_name] => \"The Unforgettable\" Jimmy Watkins
[character_id] => 8)
[2] =>
Array ([character_name] => Romie Rains
[character_id] => 7)
[3] =>
Array ([character_name] => Monica Dawson
[character_id] => 6)
[4] =>
Array ([character_name] => \"The Outlaw\" Mike Mayhem
[character_id] => 5))
编辑:任何人想要试一试?
等丢失,不能得到理想的结果仍然
我想你想'order_by('top5.ranking'); ' –
我假设最后一天是24日? – genesis
“最后一天”是指当前日期还是昨天?或表中的最后录制日期? –