So I got this query:
$CI->db->where('user_id', $CI->session->userdata('user_id'));
$CI->db->where('amount >', 0);
$CI->db->order_by('ur_time', 'desc');
$CI->db->group_by('resource_id');
$query = $CI->db->get('users_resources');
$resources = $query->result();
My problem is: The order_by 'ur_time' doesn't really work. If I got 2 rows, one with amount 10000 and ur_time 1384303464 and another row with amount 100 and ur_time 1384304656 I still get the row with amount 10000 as result.
What am I doing wrong?
EDIT: Maybe I have to explain it a bit. Let's say I got some rows:
ur_id | ur_time | user_id | resource_id | amount
1 | 1384304656 | 1 | 1 | 100
2 | 1384303464 | 1 | 1 | 10000
3 | 1384303464 | 1 | 2 | 200
4 | 1384304656 | 1 | 2 | 20000
What I'd like to get here as result: Two rows, the one with ur_id 1 and the one with ur_id 4 because for each resource_id I want the row with the highest ur_time. I hope it's clear now.
PS: I need the amount > 0 clause because there can be negative amounts but I don't want them in the result.