You don't need the foreach loop. Once you have all the values in an array you can just use the in_array() function: http://us3.php.net/in_array
Also there is a problem with your while loop. If there are multiple rows returned the way you have it written will just overwrite each value with the next so $users will only hold one value and you wont be able to explode it.
What you could do is just read all the values directly into an array by changing that line to the following:
$users[] = $data->users;
then
if(in_array(3,$users)){
.....
}