Like jmcilhinney said, you have all the parts in multiple ways of doing what you need. As someone who is still learning myself I would take his suggestion and rather then just try to get what you need working analyze the code you have and ask what each line is doing you will not only find your answer but much better off for it