为什么AJAX会返回重复数据?

So, what im doing is searching for records stored in a database using AJAX, but when it prints the callback data, the first record is duplicated:

My code:

$gUser = $_GET['q'];

$connect = mysql_connect("localhost", "root", "") or die("Could not connect to the server");
mysql_select_db("socialj") or die("Could not connect to the database");

$result = mysql_query("SELECT fullname, email FROM users WHERE fullname LIKE '%$gUser%' ");

while($array[] = mysql_fetch_array ($result))
{
    foreach($array as $r)
    {
        echo $r['fullname'].' | '.$r['email'].'<br>';
    }
}

?>

JavaScript Code:

$(document).ready(function (){
$('#searchh').on('submit', function (e){
    e.preventDefault();
    var sVal = $('#search').val();
        $.ajax({
            type: 'get',
            url: 'profile.php',
            data: {q : sVal},
            success: function (data) {
                alert(data);
            }
        });
});

});

Could you guys help me? I don't know whats happening... Thanks.

Replace this

while($array[] = mysql_fetch_array($result)) {
    foreach($array as $r) {
        echo $r['fullname'] . ' | ' . $r['email'] . '<br>';
    }
}

with this

while($row = mysql_fetch_array($result)) {
    echo $row['fullname'] . ' | ' . $row['email'] . '<br>';
}