You can do this with USB or Bluetooth tethering on jailbroken iOS devices using an app such as MyWi. There are many other jailbreak apps for this function, so it's worth shopping around.
Some will only share the 3G internet connection, but I understand others will share any internet connection over USB or bluetooth.
You can't use wifi tethering to connect your computer to a wifi network your phone knows about.
The hotspot creates a new wireless network, but the iPhone is capable of attaching to only one wireless network at a time. It cannot connect to a wireless network with internet and create its own wireless network to share.
Since the iPhone is on the wireless network, though, you can get your computer on that same network since it will likely be in range.