在sql中使用COUNT时。 我得到错误未定义的索引

I am trying to make tables that display data on my web page but every timeI use the count function in my sql query I get the error Undefined index on line 19.

Position in/Library/WebServer/Documents/students/steve/Sites/tables.php on line 19

The php code looks like this.

<?php
include('db-connect.php');
include('top.php');

$query = 'SELECT   Nationality, COUNT(Position)
          FROM     2017_Crankworx_Results
          WHERE    Position = 1
          GROUP BY Nationality
          ORDER BY Nationality ASC';
$results = mysqli_query($link, $query) or die(mysqli_error($link));

echo '<table>';
echo '<th>Nationality</th>';
echo '<th>Position</th>';
echo '<br><br>';

while($crank = mysqli_fetch_assoc($results))
{
    echo '<tr>';
    echo '<td>'.$crank['Nationality'].'</td>';
    echo '<td>'.$crank['Position'].'</td>';
    echo '</tr>';
}

echo '</table>';

include('bottom.php');
mysqli_close($link);
?>

I you could tell me if there is something that not right with my code or if I am doing something else worng that would be great.

add " as Position" after "COUNT(Position)" in your SQL, or replace the index "Position" to "COUNT(Position)" at referencing the array

Either use alias to COUNT(Position) like :

$query = 'SELECT Nationality, COUNT(Position) as position
FROM 2017_Crankworx_Results
WHERE Position = 1
GROUP BY Nationality
ORDER BY Nationality ASC';

OR

Change the index in the array of your code:

while($crank = mysqli_fetch_assoc($results))
{
    echo '<tr>';
    echo '<td>'.$crank['Nationality'].'</td>';
    echo '<td>'.$crank['COUNT(Position)'].'</td>';  // CHECK THIS INDEX
    echo '</tr>';
}

Use an alias to refer to the column

SELECT Nationality, COUNT(Position) as pos ...
$crank['pos']