将PHP mysql数据显示为类别

i am trying to display data from mysql into table by categories.

For example,

Skill 1
-Staff 1
-Staff 2

Skill 2
-Staff 1
-Staff 3

I managed to display all data from the database, however, it shows multiple tables for the same skill and i am unable to correct it.

EDIT: Thanks for the replies, i have moved the table codes out of the while loop. However, now it only shows a table containing different skills and its staff data clustered together. I would like them to be categorized according to skills, thank you!

Here are my codes:

 $result = mysql_query("SELECT * FROM Acc_skills INNER JOIN Accounts ON Accounts.Role_ID = Acc_skills.FK_Role_ID INNER JOIN Skills ON Skills.Skills_id = Acc_skills.FK_Skills_ID ORDER BY Skills.Skills");

 while ($row =mysql_fetch_array($result)){
        echo'   <b><font color="blue">'.$row['Skills'].' &nbsp (Skill ID:&nbsp'.$row['Skills_id'].')</font></b>';
        echo'
    <style>table, th, td {border: 1px solid black;}</style>
    <div class="table-responsive">
        <table width="60%">
        <thead>
        <tr>
        <th width = "20%" >Engineer assign ID</th>
        <th style="text-align:center" width = "40%">Engineer</th>
        <th style="text-align:center" = "40%">Skill Level</th>
        <th> </th>

        </tr>
        </thead>';

        echo '<tbody>
      <tr>

        <th scope="row" style="text-align:center">'.$row['Acc_skills_id'].'</th>
        <td align="center">'.$row['name'].' &nbsp('.$row['FK_Role_ID'].')</td>
        <td align="center">'.$row['Level'].'</td>
        </td>


    </tr>


    </tbody>';


echo '</table><br><br>';    
echo '</div>';

Thanks in advance

You have to check if Skill_id has changed from the last processed row. If new Skill_id appears, then end current table and start new one.

<?php
function tableHeader()
{
    echo '<div class="table-responsive">';
    echo '<table width="60%">';
    echo '<thead>';
    echo '<tr>';
    echo '<th width = "20%" >Engineer assign ID</th>';
    echo '<th style="text-align:center" width = "40%">Engineer</th>';
    echo '<th style="text-align:center" = "40%">Skill Level</th>';
    echo '<th> </th>';
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
}

function tableFooter()
{
    echo '</tbody>';
    echo '</table>';
    echo '</div>';
}
tableHeader();

$prevSkillId = null;

while ($row =mysql_fetch_array($result)){
    if($row['Skill_id'] != $prevSkillId){
       tableFooter();
       tableHeader();
    }
    echo '<tr>';
       echo '<td>'.$row[...].'</td>';
       ......
    echo '</tr>';

    $prevSkillId = $row['Skill_id'];

}

tableFooter();