am not sure if it helps...
if (near end of table){
loop until end of table{
duplicated_code()
}
}else{
loop for 5 times{
duplicated_code()
}
}
function duplicated_code
{
my site code
}
this case atleast u dont have to TYPE the code twice.
another option that comes to mind(but dont know how feasible)
if (near end of table){
no_of_times=no of rows to end of table
}else{
no_of_times=5
}
loop for no_of_times
{
my site code
}