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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -