How to get rank using mysql query with PHP -
i have following code, , league rank of user based on total balance. how can this?
// set league rank user global $post; $post_author = $post->post_author; $post_status = 'publish'; $meta_key = 'balance'; $rank = $wpdb->get_var( $wpdb->prepare( " select *, @rownum := @rownum + 1 ( select sum(meta_value) balance, {$wpdb->postmeta} pm inner join {$wpdb->posts} p on pm.post_id = p.id join (select @currow := 0) r; pm.meta_key = %s , p.post_author = %s , p.post_status = %s order balance desc)x, (select @rownum := 0) r ", $meta_key, $post_author, $post_status ) );
can me?
thank you.
try that:
select round (sum(meta_value),2) balance, @currow := @currow + 1 rank {$wpdb->postmeta} pm inner join {$wpdb->posts} p on pm.post_id = p.id join (select @currow := 0) r; pm.meta_key = %s , p.post_author = %s , p.post_status = %s order balance desc
i might misunderstood mean rank if doesn't work, please explain further need.
Comments
Post a Comment