// If by "string" you mean "string",
// use the "$str =..." lines.
$str = '';
// If by "string" you mean "array",
// use the "$arr =..." lines.
$arr = array();
$result = mysql_query($sqlquery);
if (mysql_num_rows($result) == 0) {
echo 'Query found nothing';
} else {
while ($row = mysql_fetch_assoc($result)) {
$str .= $row['userid'] . ', ';
$arr[] = $row['userid'];
}
$str = trim(', ', $str);
}