If Sam was frodo's gardener, then how did he end up on the journey in the first place?
He was eavesdropping on the conversation between Frodo and Gandalf. Gandalf caught him and sent him with Frodo to keep Frodo safe. They may not show that in the movie but it's very clearly stated in the book.
he was evesdropping