缺少预填充的复选框值从我的数组(mysql/PHP)


Missing prefilled checkbox values from my array (mysql/PHP)

我正在提取数据,我有一个列(在我当前的测试中)有3行数据。我的目标是,如果用户之前选择了行业,则预先填充表单的复选框。目前,它只检查第一个结果,而不显示其他两个结果。我尝试使用while循环,但在这些情况下,表格显示所有复选框3次,如果有有3行在我的数据。我已经尝试了很多东西,但没有工作,我确信这是一个简单的修复,但不能完全看到它。

当我直接在数据库中执行mysql命令时,它给了我这些结果(对于这个例子):

industry_idindustry

    5
  • 6
  • 7

你能帮我吗?

PHP代码:

    // Create connection and pull the data from 
$dbc = mysqli_connect('localhost', 'root', 'root', 'profile') or die('Error connecting to MySQL server.');
$id = $_REQUEST['id'];
$query = "SELECT industry_idindustry FROM `industry_has_member` WHERE member_idmember = $id";
$result = mysqli_query($dbc,$query) or die(mysqli_error($dbc));
echo '<tr><td width="30%">Industries: </td><td>';
$array = mysqli_fetch_array($result);
while ( $row = mysqli_fetch_array($result) ) {
array_push($array, $row['industry_idindustry']);
}
?>
<input type="checkbox" name="industries[]" value="1" <?php if(in_array('1',$array)){echo ' checked="checked"';}?>>None</br>
<input type="checkbox" name="industries[]" value="2" <?php if(in_array('2',$array)){echo ' checked="checked"';}?>>Film</br>
<input type="checkbox" name="industries[]" value="3" <?php if(in_array('3',$array)){echo ' checked="checked"';}?>>Television</br>
<input type="checkbox" name="industries[]" value="4" <?php if(in_array('4',$array)){echo ' checked="checked"';}?>>Music</br>
<input type="checkbox" name="industries[]" value="5" <?php if(in_array('5',$array)){echo ' checked="checked"';}?>>Gaming</br>
<input type="checkbox" name="industries[]" value="6" <?php if(in_array('6',$array)){echo ' checked="checked"';}?> >Books</br>
<input type="checkbox" name="industries[]" value="7" <?php if(in_array('7',$array)){echo ' checked="checked"';}?> >Comic Books</br>

使用此命令获取industry_idindustry值的数组:

while ( $row = mysqli_fetch_array($result) ) {
  array_push($array, $row['industry_idindustry']);
}