What medicine will help if my ear hurts.?

Depends on cause. Ibuprofen is a good basic pain reliever for undiagnosed ear pain in general. If the ear pain increases when the outer ear is moved, it could be a canal infection needing prescribed drops. If deep in the ear it may be an infection requiring prescription antibiotics. If ibuprofen helps & it resolves, fine.If not have it examined.
Inner vs outer infxn. Outer ear infection=swimmer's ear can be quite painful. Mild case can be tried at home using vinegar+water (1 to 2 ratio mixture) drops: 3-4 drops 4x/day may help. If severe, need to see doc. Inner ear infection often not as painful, but often requires antibiotic. Tmj can also cause ear pain. Motrin/tylenol/aleve helps pain in general, but i can't tell what you have now. Consult doc. Good luck.