OK, I think I might see what's happening. The reason you're seeing the test account avatar is because the html has ?u=$lastpid. But I think what you want to do is check $lastpid before calling fetch_avatar_path(), like maybe:
PHP Code:
$lastpname = $lastpostinfo[lastposter];
$getlastpname = $vbulletin->db->query_first("SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = \"$lastpname\"");
$lastpid = $getlastpname['userid'];
require_once('./includes/functions_user.php');
if ($lastpid) {
$lastpavurl = fetch_avatar_url($lastpid);
}
else {
$lastpavurl = '';
}
if ($lastpavurl==''){
$lastpav = "<img src='http://3.bp.blogspot.com/-mg71OkrgNhY/Uv9zeCV4IsI/AAAAAAAABbc/zqOph-wGgpc/s1600/Batman_avatar-e1263852269689.jpg' />";
}
else{
$lastpav = "<a href='member.php?u=$lastpid'><img src='image.php?u=$lastpid' alt='$lastpname Profile'></a>";
}