Well, replace the line below:
PHP Code:
$adoptexist = $stmt->fetch(PDO::FETCH_ASSOC);
if($adoptexist == 0) $familyname[$i][$j] = "<br>";
by the correct one:
PHP Code:
$thisadopt = $stmt->fetch(PDO::FETCH_ASSOC);
if(!is_object($thisadopt)) $familyname[$i][$j] = "<br>";