根据MySQL表上的条目生成复选框

help me guys on my project in school. I want to generate checkbox based on my data in MySQL.

For example... in STUDENT table, the data are: Daniel, Jam, Minho, James, Paul.

I want to make checkboxes based on the contents of the STUDENT table.

[ ] Daniel [ ] Jam [ ] Minho [ ] James [ ] Paul <----------looks like this :)

Then once I insert another content "Samantha" on the STUDENT table, it will generate a checkbox that contains [] Samantha.

I can't search for a situation like this on the internet! I'm using PHP, HTML and MySQL (PHPMyAdmin).

I don't know if that is called dynamic or what.

$sql = "SELECT name FROM students";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)){
    echo "<input type='checkbox' name='students[]' value='".$row['name']."'>"
        .$row['name'];
}

To get that kind of checkboxes, you have to retrieve the result and embed it with HTML code.

// create connection here
$sql = 'select name from STUDENT';
$result = mysqli_query($connection_object,$sql);
while($row = mysqli_fetch_array($result)) {
     echo "<input type='checkbox' value='{$row['name']}'>" . $row['name'];
}