Only 2 stars for squad617's answer? Given that he/she has provided a remarkably accurate summary of a complex subject, that seems a bit harsh!
I'll try a different approach:
Imagine that you get a large splinter in your finger (and that you're unable to get it out). As the splinter goes in, and shortly afterwards, you might feel a sharp pain. This is because of damage to the nerve endings. However, a day or two later, you might feel a throbbing pain. This is because infection has set in, resulting in inflammation, which results in pressure on the nerves.
The best treatment for any medical condition is generally, where possible, to deal with the cause, rather than the effect. So, to alleviate the throbbing pain in your finger you should seek to reduce the inflammation. To do so, you should take an anti-inflammatory drug, such as aspirin or Ibuprofen.
However, as with the initial injury when the splinter went in, not all pain is caused by inflammation. In which case, an anti-inflammatory drug won't help at all. When a pain is not caused by inflammation the only option is to try to block the message between the nerve and the brain. That's what analgesic drugs do.
That (roughly) explains the difference between the two types of drugs. However, within each class of drugs certain preparations are better at reaching specific parts of the body than others. (It's, at least in part, to do with their molecular structure and their ability to cross certain cell walls. But I freely admit that I'm getting out of my depth with the finer points of the science!). That's why some drugs work better on certain types of pain than others.
That's nowhere as good as Sqad617's answer but I hope that it might usefully add to it.
Chris