1

I want to get records after a certain record, say id is 4.
Actually I want to show posts based on likes with pagination.

So I sorted result by likes.
But I don't know how to get the next records based on id.

Here is my code

SELECT urp.* , likes
FROM user_related_posts urp
JOIN (
    SELECT post_id, COUNT(*) AS likes
    FROM post_likes
    WHERE STATUS =1
    GROUP BY post_id
    ) v ON urp.post_id = v.post_id
GROUP BY post_id
ORDER BY likes DESC 
LIMIT 0 , 30

Sorry I don't put image, I don't have enough credentials.

What here doing is when I order with likes, ids are unsorted, but I want records based on id. Image Link

Image Link

Community
  • 1
  • 1
Venkatesh
  • 108
  • 1
  • 10

2 Answers2

1

You can use LIMIT so that you can retrieve it like pagination

anjnkmr
  • 838
  • 15
  • 37
0

You can use date_created in your query.

SELECT        *
FROM            post_likes
WHERE        (date_created >
                             (SELECT        date_created
                               FROM            post_likes AS p1
                               WHERE        (id= 4)))

Note :

I have not added the entire code.Please use the code and edit as your requirement.

Tharif
  • 13,794
  • 9
  • 55
  • 77