Okay to start off you will need to be a bit more specific with your question. Has your iPhone come into contact with liquid? How long has this issue occurred for? Have you dropped your iPhone? Answers to simple questions like that drastically help people answering the big question at the top of the page. However i will try my best to answer with what you have described.
Sounds to me as a battery problem. Because you do have a 3G model, your iPhone is probably several years old, and like all batteries, they do have an expiration date.
Here is a link to the part you will need to replace and here is a link to the repair manual on how to replace it. If you are not 100% familiar with internals of an iPhone DO NOT replace it yourself. I have seen many people with very minimal experience try to fix their phone and end up permanently breaking it in the process. Take it to an iPhone repair store if this is the case and they should be able to do the replacement for about $50-$80.
Hope this helps! :)