How to get rid in the while (mysql_fetch_array) i use the exit but did not work.

In this code "exit" works.
Code:
    while ($counter < 10)
     {
        if ($counter == 5)
        {
             exit;
        }else
        {
             echo $counter
        }
     }
While in this code "exit" doesn't work. Cause when the codition meets it supposed to stop the while statement, but it wont stop it will continue the looping.
Code:
       while ($fields = mysql_fetch_array($sql))
       {
            if ($fname == $fields['fname'] && $lname == $fields['lname'])
            {
                 echo "welcome"
                 exit;
            }
       }