Some people look upon prayer as a cosmic wish list. They believe if they ask nice enough, have been good enough, and have enough faith, then God will gladly give them whatever they ask for. The Bible teaches no such thing.
It is not unusual to hear someone say, "I prayed about my problem, but God did not hear or answer my prayer." Are you sure God did not hear your prayer, or did He just give you an answer other than "yes"? Lest we begin to think God does not care about us or our needs, we need to remember there are at least four different ways God can answer our prayers.
1. "YES." There are many times when God will answer "yes" to our prayers. It is God's good pleasure to grant the petitions we ask of Him (Matt. 7:7-8). This does not mean such an answer has come unconditionally. Our request must be made in faith (James 1:6-8), our request must be according to God's will (1 John 5:14-15), and we must be doing God's will in our life when we ask (1 John 3:22).
2. "YES, BUT NOT YET." We are all familiar with the well-know saying "Timing is everything." This certainly applies to prayer. God, in His divine love and wisdom, may see fit to delay answering our prayers. There are several reasons for this. Having to wait can be a means of developing and strengthening our faith. We may not be mature enough to handle the thing for which we have asked. There may be a larger purpose that God intends to bring about. Whatever the reason, we must accept by faith the fact God hears and cares, and He will respond according to His own wisdom in His own time.
When the answer seems to be "Yes, but not yet," we need to remember God's promise (Phil. 4:19), continue to exercise patience (James 5:10-11), and keep on asking (Luke 11:5-10).
3. "YES, BUT SOMETHING DIFFERENT." God will sometimes answer our prayers in a way different (better) than we have in mind. We must be careful not to put God in a box or dictate exactly how He is to answer our prayers. We must remember God has a perspective, wisdom, and power above anything we can even imagine (Eph. 3:20). Also, we do not always know what we should pray for or how to pray for it (Rom. 8:26).
God's ways are higher than our ways (Isaiah 55:8-9). As we pray, our trust in God should allow Him the latitude to answer however He sees best. If we put God in a box and look for His answer there, we may miss the answer He has given to our prayers elsewhere.
4. "NO." There may be times when God has to deny our request. Why would God do such a thing? Perhaps we have asked from selfish motives (James 4:3). Perhaps, as our Father, He has told us "no" to protect us (Heb. 12:9-10). Perhaps we have failed to seek God's will and purpose (1 John 5:14-15). Perhaps we need to learn to appreciate what we already have. Paul prayed three times that the Lord would remove his "thorn in the flesh." He was told "no," and was made to understand that he needed the "thorn in the flesh" to make him better (2 Cor. 12:7-10).
Conclusion: Do not ever lose your faith in prayer. Prayer works, if we will work it. However, we must remember that God is the one at work in our prayers. His will must be done. Understanding how God answers prayer is a part of understanding and appreciating prayer. However God chooses to answer our prayers, we must have confidence that it is for our own good.