You are having the same issue I ran into when I was echoing out mootools dropdown menus for refbacks
Lynne hit the nail on the head, you MUST have unique IDs. So you need to set things up in an array, then to echo out the ID. So you want it to increase by one number or so fourth.
If you Google it you will find tons of documents and whatnot on how to customize your javascript and add the PHP.