To answer the main question... YES, you can nest while loops, but make sure the expression used in each are not shared variables of each, as then you can get some unpredictable behavior if it is not your intent.
A simple nested while to do a factoral like action:
$total = 10;
$c = 0;
$n = 0;
while ($c < $total) {
while ($n < $total) {
//do stuff n times for each c time
echo "ping!";
$n++;
}
$n = 0;
$c++;
}
This should echo "ping!" 100 times. A crude example, but yes, possible and safe, so long as you dont screw something important up ;-) hehe.
As for you issue with getting something out of the database in regards to something in an array? Im not too clear on what it is you were trying to describe, so I cannot answer on that.