php - How to get rank according to count in mysql -


i getting issue fetching rank according count.

i have 2 tables :

1)images 2)images_like 

now if images_like have no entries showing "null" in ranks. please check query , output :

select im.id,     rank    (select image_id,                 @rownum := @rownum + 1 rank,                 count(*)               cnt            images_like,                 (select @rownum := 0) r          group  image_id          order  `cnt` desc) d         right join images im                 on d.image_id = im.id  

enter image description here

i need display 3 not null ....

thanks in advance !!!!!

try :

select im.id, d.rank   (                    select t.image_id, @rownum := @rownum + 1 rank              (                          select image_id,                   count(*) cnt              images_like           group  image_id            order  `cnt` desc) d                ) t,       (select @rownum := 0) r           ) d      right join images im on d.image_id = im.id    

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -