I was able to fix it. I had to specify which match to review. Thanks for the help.
function BrewIdFinder($matches){
$sweet= substr($matches[0], 2);
$result3 = mysql_query("SELECT brew_id FROM places WHERE screen_name like '".$sweet."'");
$num_rows1 = mysql_num_rows($result3);
if($num_rows1==0){
$x= ' <a href="http://twitter.com/'.$sweet.'" target="_new">@'.$sweet.'</a>';
}else{
while($row = mysql_fetch_array($result3))
{
$brewid= $row['brew_id'];
}
$x= ' <a href="http://www.brewzinga.com/places/'.$brewid.'" target="_new">@'.$sweet.'</a>';
}
return $x;
}