From history it seems that you might be having some ligamental tear, cartilage
damage or some soft tissue
Go for x-ray of affected knee and find out the cause.
After report go for treatment accordingly.
Give rest to the part.
Avoid bending from affected knee.
Do patellar exercise.
Do ice cold
application for few days.
Ok and take care.