After our sun formed, there would have been lots of rock, metals, gases and liquids scattered in space around the sun. Over time, the bits would have started sticking together and then as they got larger and larger, they would have developed a stronger and stronger gravitational force that would have pulled more and more bits of matter in. Slight movement would have started them spinning and they would have been attracted towards the sun too so that they would have been spiralling in towards it. I dont know what they stopped them from being pulled all the way in, but i guess its a balance between their tendancy to want to be thrown outwards by their circular path and the pull from the sun. Eventually, these balls would have turned into planets and their orbits stabilised in their current positions.