I've got a script for you.
I'm not good with maths... but... I did it

Code: Select all
<?php
$total_people = 107;
$total_lines = sqrt($total_people);//square root of total people
$position=0;
for ($i=0;$i<$total_lines+1;$i++){ //lets build the lines
if ($position < $total_people){//if there's still people that need a position...
$this_line = pow(2, $i);//the power of the current line (will be the total people o it)
echo "ROW - ".$i." --> <p>";
for ($j=0;$j < $this_line;$j++){
if ($position < $total_people){//if there's still people that need a position...
$position++;
$my_array[$i][]=$position;//feed the array
echo $position." - ";
}else{
break;//get out of the array because no more people need a postition
}
}
echo "<br>";
}else{
break;//get out of the array because no more people need a postition
}
}
echo "<pre>";//the shape of the array
print_r($my_array);
echo "</pre>";
?>
execute this code and use it as you need.
As you see there is an array ordered by rows and numbers. Each number can be the "id" for a name in a database, so you can access positions and do whatever you want with them.
I hope it helped!
;)