I have googled and looked at SO for a while now and can't seem to figure this out. The only requirement Im trying to meet is to return a properly formatted javascript array that contains the results of the sql statement. 

I.E. 

Given a query:

```
SELECT NUMBERS FROM TABLE 

```

And results:

```
NUMBERS
1
2
3

```

I would like to eventually get back an array like so

```
["1","2","3"]

```

Please help me understand where I am going wrong

Here is my php code

```
<?php

$mysqli = new mysqli("local.host.com", "user", "pass", "db");

$sql = "SELECT DISTINCT NAME FROM table";

$result = $mysqli->query($sql);

while($row = $result->fetch_array())
{
    $rows[] = $row['NAME'];
}

echo(json_encode($rows));

$result->close();

/* close connection */
$mysqli->close();
?>

```

Here is my javascript:

```
    function GetCards()
{
    var cardarray = new Array();

    //alert('test');
    $.getJSON('getcardlist.php', function(data)
    {
        for(var i=0;i<data.length;i++)
        {
            cardarray.push(data[i]);
        }

        //return cardarray;

    });

    return cardarray;
}

```

EDIT:

Little more information, Im trying to setup an autocomplete list for jquery ui, this is my setup for the autocomplete widget.

```
var list = GetCards();

$( "#name" ).autocomplete({
source: list,
minLength: 2

```

And this is the error Im getting from chrome console 

```
Uncaught TypeError: Cannot read property 'label' of null 

```