如何根据数据库结果设置多个PHP复选框?

I wanna edit an info of a checkbox in a page but when I clicked the edit link I want the already selected multiple checkbox from the database to be set as checked. But the result I get from my code is that only the last selected checkbox is set as checked(ticked) instead of all the selected checkbox.

Here's my code:

<td><input type = "checkbox" name = "checkbox[]" value = "Badminton" <?php if($interest == 'Badminton') echo "checked = 'checked'"; ?>/>Badminton</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Baseball" <?php if($interest == 'Baseball') echo "checked = 'checked'"; ?>/>Baseball</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Basketball" <?php if($interest == 'Basketball') echo "checked = 'checked'"; ?>/>Basketball</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Cricket" <?php if($interest == 'Cricket') echo "checked = 'checked'"; ?>/>Cricket</td>
<td><input type = "checkbox" name = "checkbox[]" value = "Football" <?php if($interest == 'Football') echo "checked = 'checked'"; ?>/>Football</td>

and heres my sql code:

$sql = "SELECT * FROM interest where username = '$username'";
$result = $conn->query($sql);
if($result->num_rows > 0)
{
    while($row = $result->fetch_assoc())
    {
        $interest = $row['interest_name'];
    }
}

You can store your values in to an array then you can use in_array() to check:

<?php
$interest = array(); // initializing  
while($row = $result->fetch_assoc())
{
    $interest[] = $row['interest_name']; // store in an array
}
?>

HTML:

<td>
     <input type = "checkbox" name = "checkbox[]" value = "Badminton" <?=(in_array('Badminton',$interest) ? 'checked="checked"' : '')?> />Badminton
</td>

Side Note: Change other checkbox as same above with different values which you have.

First of all your if you want to use all the values coming from your query you need to store them in an array something like:

while($row = $result->fetch_assoc())
{
    $interest[] = $row['interest_name'];
}

Now when it comes to your html you can go like:

<td><input type = "checkbox" name = "checkbox[]" value = "Football" <?php if(in_array('Football',$interest)) echo "checked = 'checked'"; ?>/>Football</td>

Just the first example, you should do it in all of them.