PHP Code:
$numberOfEntries = getNumRows("photopost_photos", "id > 0");
$desirednumber = $numberofentries - 12;
Gotcha, PHP is a case-sensitive language
$numberOfEntries and $numberofentries are totally different variables. This little mistake lead to catastrophic consequences later in the script, namely to what I believe is a simple out-of-memory error during the execution of getRows(). Anyway, I hope this fixes it.