i wish to help u with this but im having a bit of difficulty understanding ur problem.
i've been doing while loops for this problem
what exactly is 'this problem'?
are u trying to retrieve a set of 'boxes' from a mysql database and arrange them in order?