iPhone mismatch between settings showing connection to Wifi SSID and 3G in Top left hand corner showing not connected
This has always been a slight quirk with various models of the iPhone. What version of the iPhone are you running, both hardware and software?

I've experienced this exact issue previously on the iPhone 3G. It seemed that, when the phone is but to sleep, it powers down the wifi to preserve battery, and upon wake, the Wifi indicator doesn't immediately update. There may also be a short lag in reconnecting to the Wifi after wake as well. I've actually taken the phone back and had it replaced to try and resolve this issue on one handset that suffered from it particularly badly. The replacement was better, but still showed some of this behaviour.