Php 为foreach()提供的参数无效-但正在显示输出

Php 为foreach()提供的参数无效-但正在显示输出,php,arrays,foreach,Php,Arrays,Foreach,我正在根据查询结果显示可编辑字段。我知道查询运行正常,并且返回了一个数组。数组正在正确填充表单字段,但是,我收到了“为foreach()提供的参数无效”警告。我对这一点还不熟悉,对正在发生的事情一无所知。我感谢你的建议 代码如下: // Grab the profile data from the database $query8 = "SELECT * FROM EDUCATION WHERE ID_NUM = '" . $_SESSION['IDNUM'] . "' ORDER BY REC

我正在根据查询结果显示可编辑字段。我知道查询运行正常,并且返回了一个数组。数组正在正确填充表单字段,但是,我收到了“为foreach()提供的参数无效”警告。我对这一点还不熟悉,对正在发生的事情一无所知。我感谢你的建议

代码如下:

// Grab the profile data from the database
$query8 = "SELECT * FROM EDUCATION WHERE ID_NUM = '" . $_SESSION['IDNUM'] . "' ORDER BY RECORD";
$data = mysqli_query($dbc, $query8);

echo '<pre>' . print_r($data, true) . '</pre>'; 
$rowcount = 1;
while ($row = mysqli_fetch_assoc($data))
{
    if (is_array($row))
    {
        echo '<p> It is an Array</p>';
    }
    foreach($row as &$item)
    {
        $record = $row['RECORD'];
        $school = $row['SCHOOL'];
        $type = $row['TYPE'];
        $degree = $row['DEGREE'];
        $major = $row['MAJOR'];
        $grad = $row['GRAD'];

        ?>
        <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

        <fieldset>
        <legend>Education History </legend>
        <?php
        echo '<input type="hidden" id="record" name="record" value="' . $record . '">';
        echo 'Rowcount' . $rowcount. '</br>';
        // Insert Listbox here
        $queryschool = "SELECT * FROM SCHOOL";
        $list = mysqli_query($dbc, $queryschool);
        if($list) 
        {
            echo 'School Type? ';
            echo '<select name="school_code">';
            while($row = mysqli_fetch_assoc($list))
            {
                echo "<option value={$row['CODE']}>{$row['TYPE']}" ;
                echo '</option>';
            }
            echo '</select>';
        }

        echo '<br />';
        echo '<label for="school">School Name:</label>';
        echo '<input type="text" id="school" name="school" size="40" maxlength="40" value="' . ( (!empty($school)) ? $school : "") . '" /><br />';

        // Insert Listbox here
        $querydegree = "SELECT * FROM DEGREE";
        $list = mysqli_query($dbc, $querydegree);
        if($list) 
        {
            echo 'Degree Type? ';
            echo '<select name="degree_code">';
            while($row = mysqli_fetch_assoc($list))
            {
                echo "<option value={$row['CODE']}>{$row['DEGREE']}";
                echo '</option>';
            }
            echo '</select>';
        }
        echo '<br />';
        echo '<label for="major">Field of study:</label>';
        echo '<input type="text" id="major" name="major" size="40" maxlength="40" value="' . ( (!empty($major)) ? $major : "") . '" /><br />';
        echo '<label for="grad">Did you graduate?:</label>';
        echo '<input type="radio" id="grad" name="grad" value="Y" ' . ($grad == "Y" ? 'checked="checked"':'') . '/>Yes ';
        echo '<input type="radio" id="grad" name="grad" value="N" ' . ($grad == "N" ? 'checked="checked"':'') . '/>No<br />';
        ?>
        </fieldset>
        <?php
        $rowcount++;
    }
}
;
echo '<label for="another">Do you need to enter more educational experience?:</label>';
echo '<input type="radio" id="another" name="another" value="Y" ' . ($another == "Y" ? 'checked="checked"':'') . '/>Yes ';
echo '<input type="radio" id="another" name="another" value="N" ' . ($another == "N" ? 'checked="checked"':'') . '/>No<br />';

?>

<input type="submit" value="Save Profile" name="submit" />
</form>
//从数据库中获取配置文件数据
$query8=“从教育中选择*,其中ID_NUM=”$_会话['IDNUM']。“‘按记录订购’;
$data=mysqli_查询($dbc,$query8);
回显“”。打印($data,true)。“”;
$rowcount=1;
while($row=mysqli\u fetch\u assoc($data))
{
if(is_数组($row))
{
echo'它是一个数组;
}
foreach($row as&$item)
{
$record=$row['record'];
$school=$row['school'];
$type=$row['type'];
$degree=$row['degree'];
$major=$row['major'];
$grad=$row['grad'];
?>
foreach($row as&$item)
应为

while ($row = mysqli_fetch_assoc($data))
{

$record = $row['RECORD'];
$school = $row['SCHOOL'];
$type = $row['TYPE'];
$degree = $row['DEGREE'];
$major = $row['MAJOR'];
$grad = $row['GRAD'];
}
这里没有必要使用foreach,你可以这样做

foreach($row as $item)
 {
  $record = $item['RECORD'];
  $school = $item['SCHOOL'];
  ....

您没有更改行项目,因此不要通过引用传递给foreach。另外,您不应该使用$item而不是$row吗?请执行以下操作:

foreach($row as &$item)
  {
  $record = $row['RECORD'];
  $school = $row['SCHOOL'];
  ....
不要这样做:

foreach ($row as &$item) 
将其替换为:

$record = $row['RECORD'];
然后,对于每个变量,您可能需要更改

$record = $item['RECORD'];


当我更改为使用$item['field']表单的输出将截断该数据并乘以迭代次数?我希望能够通过表单更改数据。该更改确实消除了错误消息。现在的问题是,字段集的每个实例中的单选按钮都作为一个单选按钮运行。在一行上选择“是”将取消选择所有其他行。我的下拉列表将取消选择n框不会默认为以前选择的项目,并且通过“提交”按钮,不会保存任何更改。
$record = $row['RECORD'];
$record = $item['RECORD'];