The error you were getting is because the db object isn't defined, which usually is because $vbulletin isn't in scope. The new error is because you're missing a close quote on the query string. Try this:
PHP Code:
<?php
global $vbulletin;
$groupid = 43;
$users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids)";
$str = '';
$sep = '';
while ($user = $vbulletin->db->fetch_array($users))
{
$str .= $sep . $user['username'];
$sep = ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users);
echo "Market Banned: $str";
?>
That assumes that what you posted is only part of a page (like it's included or it's plugin code or something). If you're trying to make a stand-alone page then you need to inlucde global.php. (If you are trying to make a page you might want to look at this:
https://vborg.vbsupport.ru/showthread.php?t=228112).