Where did you get this part?
//This code will count how many rows will satisfy the current query.
$query ="SELECT * FROM `photos` WHERE `thumb_id` = '3'";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data;
That doesn't look right. It should be selecting a COUNT or else using mysql_num_rows. Since the rest of the page numbers are based upon the $numrows variable, it needs to have the right number here. Echo it to see if it's what it should be.