You have set $buttonName and $url before the while loop, so they will not change no matter what button is current.

Also, you want the </ul> after the end of the while loop.