I read a book (I have already mentioned it in a post) which gives some reasons why our prayers are not answered or our wishes are not granted. You may not agree with them but I feel they have a comforting effect.
One of the reasons is: Granting you your wish could harm you.
The reason might be beyond us mortal ignorant beings.
Perhaps it is like parents not allowing their children to do certain things.
In my school years my father was strict. Coming home late was not allowed or must get permission first. Red marks in report books meant getting long scoldings and frequent reminders to study hard. Punishment - not allowed to go to the cinema, one of the few entertainments then, for one month.
Authoritarian parents were common in those days, but it was not a bad thing altogether.