Question: I want to save my data into an array and then sort it and display to user

Please help me out i am new in php

My code is :

```
$sql = "Select * FROM contact_info WHERE user_id = $userid AND name LIKE 'a%' ORDER BY name ASC";
$result=mysqli_query($con,$sql);

$a = array ();
$i=0;
while ($row=mysqli_fetch_array($result))
{
    $a[$i]=$row['name'];

}
sort($a);
for ($i=0; $i<mysqli_num_rows($result); $i++)
{
    echo $a[$i]  . '<br>';}

}

```

error comes after this code:
Notice: Undefined offset: 1 in C:\\ on line 51...so on...

Answer: 
```
while ($row=mysqli_fetch_array($result))
{
    $a[$i]=$row['name'];
    $i++; // forgot this
}

```
Inside the while you need to increment $i.