Select the image table from the db, If no image is there then output the default image, if not then show the real image
if($row['image']){
$petimage= "[img=images/" . $row[]";}
else{
$petimage= "[img=images/mynoimage.gif]";
}
Something along those line's, You'd need to do the select query and change stuff though