break;
is your friend
http://php.net/manual/en/control-structures.break.php
while($rows=mysql_fetch_array($result)){
if (
$row['username'] == 'username'
) {
break;
}
}
An alternative approach depending on your intention would be to just change the SQL query to do what you want instead, i.e. something like the following which uses the @includeThis variable to keep track of if it's hit the intended username yet
$sql="
SELECT
u.*,
@includeThis AS includeThis,
@includeThis := IF(u.username = 'TargetUserName',0,@includeThis) AS updateIncludeThis
FROM users u, (SELECT @includeThis := 1) d
ORDER BY u.score DESC
HAVING includeThis = 1
";
Additionally you shouldn't be using the mysql_ functions any more, and instead using mysqli_ or PDO. Why shouldn't I use mysql_* functions in PHP?