Your only showing us part of your code, are you incrementing $index by one etc ? Lets see the entire routine.