I have terrible pain on my knees and ankles every few months. I am unable to walk during it. Pain killers are not very effective any ideas what it is?

More info. Have you noted a cyclic pattern? Worse before or after activity? I would suggest starting with your pcp for some routines to determine if there may be a systemic cause.
Many possibilities. Your pain could be as a result of many different things. A thorough history and physical exam and possibly some laboratory and radiology exams are needed to determine the exact cause. Causes of pain may include: trauma (fracture, sprain, arthritis), infection, metabolic conditions (gout), musculoskeletal or biomechanical abnormality and neurologic conditions (neuropathy).