Is there any way to implement a Next Prev navigation on a detail page of an ordered result set so that the links take you to the next or prev record?

I can set up the navigation for the results page but would appreciate some help to achieve the same for the detail page?

I tried adding row numbers to the SQL :

SELECT @i:=@i+1 as row_num, ....
but this doesnt appear in sequence i.e. 1,2,3... if the SQL is sorted using an ORDER BY clause.