开发者

Stack Overflow functionality how-to: create link to user's answer on OP's questⅰon from user's profile page

I am trying to implement something similar to a functionality on Stack Overflow.

On a user's profile page, where there are listed the Answers by user, when you click on the link to question, you are redirected to the quest开发者_StackOverflowion page and the answer is highlighted.

Stack Overflow functionality how-to: create link to user's answer on OP's questⅰon from user's profile page

This works even if the answer clicked on happens to be lying on like 2nd page below, the page is displayed.

Stack Overflow functionality how-to: create link to user's answer on OP's questⅰon from user's profile page

How can I implement this? The only way I can think of right now is by implementing the following steps:

When listing the answers by a user..

  • Find out the list of answers to every question the user has answered
  • Sort the list
  • Find out where the answer by user lies in that list
  • This number can be to create a link to the page where answer by the user lies on question page

But this seems very memory-consuming process. Is there an easier way to do this?


There's no 4-step process, you just make one database query for the user's answers from your answers table. The question ID is part of the same row, so you have everything you need to link to the question and pass on the ID of the answer to highlight.


That's the idea.

You have to retrieve the results for the whole page, because you're displaying the whole page. You have to sort as well, because that's what you do when you display a page. And in that case, you'll know which page your desired answer is own because of how far down it is in the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜