Sunday, November 10, 2019

mysql 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 .



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 question page and the answer is highlighted.
Answer by a user



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



Paged answer




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?


Answer



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.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...