I am usually against using stored procedures in MySQL since I think they are not mature enough but I think this is a classic case to create one.
We are still required to have two queries, one for getting the comment's order and one for fetching the relevant rows but I could not find of anything more creative for having it done within 1 single query since the LIMIT values have to be known before executing the query.
In cases when we are not talking about huge results sets then it might be more efficient to simply fetch all results and the comments order and then use array_slice for displaying only the relevant page comments.
/* get the comment order */
SET @commentOrder = 0;
SELECT commentOrder INTO @relevantCommentOrder FROM (
SELECT commentID, @commentOrder := @commentOrder+ 1 as commentOrder
FROM COMMENTS
ORDER BY creationDate) commentsOrder
WHERE commentID= 45;
/* get the value we want to use in the LIMIT clause */
SET @startFrom = CONVERT(ROUND(ROUND(@relevantCommentOrder/10)*10) ,UNSIGNED);
/* fetch relevant results */
PREPARE STMT FROM 'SELECT * FROM COMMENTS LIMIT ?,10';
EXECUTE STMT USING @startFrom;
The next one is 1 query that would get you the whole results set and put the comment's order in all rows so you could then just check the first row's relevantCommentOrder field inside PHP and then slice the array so it'd display only relevant comments, this one is only efficient if the whole results set is not too big.
SET @commentOrder = 0;
SELECT *, @relevantCommentOrder;
FROM (
SELECT commentID, @commentOrder := @commentOrder+ 1 as commentOrder,
@relevantCommentOrder := case when commentID = 45
then @commentOrder
else @relevantCommentOrder end
FROM COMMENTS
ORDER BY creationDate ) subQuery;