The farther you go from the sun the slower the planets are moving. Mars and Jupiter do have longer years than earth because the circle they travel in is larger, but they also travel more slowly. This means that when the Earth and Mars come close to each other in their orbits the Earth gradually passes Mars.
Since Mars moves in its orbit, traveling in the same direction as earth, from Earth it seems that Mars is slowly passing stars just as an airplane passes in front of mountains. As we catch up to Mars and pass, it seems for a bit that Mars moves backwards just as from a jet, a small plane seems to move backwards as you pass it. Then as we move away ahead of Mars we see that Mars is again catching up to stars and passing them from our point of view.
Thus, from our point of view Mars moves backward for a few days, then seems to turn and move forward again. This was a major problem for early astronomers until the idea of orbits around the Sun was accepted. Previously, people presumed that planets moved in little circles called epicycles as they traveled around the earth.