从多维数组中捕获值并将其显示在提交表单时最初输入的文本字段中时出现问题


Trouble with catching values from a multidimensional array and display it in the text field where it was originally entered when form was submitted

我需要有关如何在用户提交后输入值的文本字段中保留输入值的帮助。我很难弄清楚如何保留这些值,因为当我单击提交按钮时,页面刷新,然后值消失,我必须再次重新键入它们。

以下是我的表格:

 <?php $count_name = count($x); ?>
 <table>
  <thead>
   <tr>
     <th colspan="<?php echo $count_name; ?>"><strong>MR</strong></th>
     <th colspan="<?php echo $count_name; ?>"><strong>MS</strong></th>
  </tr>
  </thead>
  <tbody>
  <?php $_college = mysql_query("SELECT * FROM college");
        if(mysql_num_rows($_college)) {
        $i=0;
        while($row_college=mysql_fetch_array($_college)) { ?>
   <tr>
    <?php for($j=0;$j<$count_name;$j++) { ?> 
     <td>
        <input type="text" name="mr<?php echo $j; ?>[]" value=""/>
     <td>
     <?php } for($k=0;$k<$count_name;$k++) { ?> 
     <td>
        <input type="text" name="ms<?php echo $k; ?>[]" value=""/>
     <td>
     <?php } ?>
   </tr> 
 <?php } $i++;} ?>
 </tbody>
 <table>
 <input type="hidden" value="<?php echo $count_name; ?>" name="totrows"/>
 <input type="submit" value="Submit" name="submit"/>

这是我的代码,如果按钮提交是点击

<?php
if(isse($_POST['submit'])) {
$y = $_POST['totrows'];
$count_totcriteria = $y;
for($ab=0;$ab<$count_totcriteria;$ab++) {   
    $mr = 'mr_'.$ab;
    $ms = 'ms_'.$ab;
    $mr_score = $_POST[$mr];
    $ms_score = $_POST[$mr];
    foreach($mr_score as $key1 => $val1) {
        if(is_numeric($val1) && !empty($val1)) {
            $mr_val[] = $val1;
        } else {
                $msg = 'All fields are required and must be a valid score';
            }
    }
    foreach($ms_score as $key2 => $val2) {
        if(is_numeric($val2) && !empty($val2)) {
            $ms_str[] = $val2;
            } else {
                $msg = 'All fields are required and must be a valid score';
            }
        }           
    }
}

我知道我必须在"value=""中放入一些代码,以便在提交表单时显示输入的值,但我不确定要使用什么代码。不确定如何捕获每个数组值。

我认为而不是

<input type="text" name="mr<?php echo $j; ?>[]" value=""/>

你正在寻找这样的东西(假设$i是你的新外循环)

<input type="text" name="mr_<?= $j ?>[<?= $i ?>]" value="<?= @$_POST['mr_'.$j][$i] ?>"/>

以及ms线的相同变化。

这行得通吗?