for some reason if i didn't have that then if amount = 6 then $perrow ended up as 5
Yes, that is what would happen. The thing is, you have unreachable code (i.e., the else branch).
Consequently, you should remove that unreachable code:
if ($row['type'] == 'puzzle' && $row['amount'] == 15)
$perrow = 3;
elseif (($row['amount'] % 5) == 0)
$perrow = 5;
elseif (($row['amount'] % 4) == 0)
$perrow = 4;
elseif (($row['amount'] % 3) == 0)
$perrow = 3;
elseif (($row['amount'] % 2) == 0)
$perrow = 2;
else
$perrow = 1;
Alternatively, you could use a loop:
if ($row['type'] == 'puzzle' && $row['amount'] == 15) {
$perrow = 3;
} else {
for ($i = 5; $i > 0; --$i) {
if ($row['amount'] % $i == 0) {
$perrow = $i;
break;
}
}
}