Okay, here is the problem:

Certain questions contain more than one page's worth of answers. Given a sort method and an answer id, how can we figure out which page the answer is on?

Any suggestions are welcome.

  • have you resolved? Jun 24, 2010 at 8:27
  • I guess so... doesn't look like there's an easy way. Jun 24, 2010 at 16:34

3 Answers 3


These are two simple methods in meta-language:

1. Pulls a pagesize number of answers, page after page, checking the presence of the given accepted_answer_id

def get_accepted_answer_page(question_id, answer_id, sort, pagesize):
   page = 1
        answers_page_ids = get_answers_ids_with_API_method(question_id, sort, page, pagesize)
        if accepted_answer_id in answers_page_ids : return page
        else: page ++

2. Pulls all the answers ids using the fastest/lightest API method (questions/id/answers, pagesize=100, body=false..), get the index of the accepted_answer_id on this list and finally find the page dividing accepted_answer_id position by the pagesize

def get_accepted_answer_page(question_id, answer_id, sort, pagesize):
   answers_ids = get_all_answers_ids_with_the_fastest_lightest_API_method(question_id, sort)
   accepted_answer_id_position = get_accepted_answer_index (answers_ids) + 1
   accepted_answer_page = (accepted_answer_id_position / pagesize) +1 
   if accepted_answer_id_index MOD pagesize == 0 : accepted_answer_page --
   return accepted_answer_page

My 0.02c


Why go through the question to get an answer you already have?

You have an answer id, so you can get all of its information.

  • Suppose that the answer id is passed to a web app via a URL. You want to show the page of answers that has that answer answer. How can that be done? Jun 22, 2010 at 21:45
  • @George Edison - hmm, if the sort if votes it can't be done; since answers with the same score are randomly ordered there is no canonical page. If its anything else, binary search w.r.t pages would be fastest. I still think its a pretty arbitrary thing to do. Jun 23, 2010 at 1:12
  • It's for my Mobile Site if that helps. I get URLS like http://...../questions/xxx#yyy where yyy is the answer number. This way I have a named anchor on the page that the browser can jump to. Jun 23, 2010 at 1:31

I suppose you could pull all answers from a question and store them in a list is a static sorted order. Then, you would know the page the answer is on given the entire list.

It is far less memory efficient, but it will be much easier to figure out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .