If you're having problems connecting the iPhone to a Wi-Fi access point that's within your control, try switching the access point's wireless security protocol from WEP to WPA. A number of readers have reported more stability and better throughput when using the latter.
iPhone Atlas reader Gregg writes:
"I had a lot of problems getting my iPhone to work with WEP. It worked for about 4-5 days...then it started getting really flakey, failing to hold a web connection or a mail connection, bizarre. I tried everything hex, hex(PC), ascii, finally I just decided to move over to WPA (my router has both WEP and WPA...) bingo no problems, it instantly found the wireless connection and my network connection is good."
You may also want to peruse Apple's Knowledge Base article "Tips when using Wi-Fi"