将选择输入数组从视图传递到控制器(Codeigniter)

时间:2014-05-15 14:58:19

标签: php arrays codeigniter select

正如标题所示我正在尝试将<select>中的值数组从视图传递到控制器以进行批量插入 以下是视图类的部分片段:

       foreach($results as $row){echo '<tr>';       
    echo '<td> <select name="Select[]" value="'.$count.'" >
            <option value="Select">Select</option>}
             <option value="P">P</option>
             <option value="F">F</option>
            </select></td>';
    echo '<td> <select name="Select2[]" value="'.$count2.'" >
            <option value="Select">Select</option>}
             <option value="A">A</option>
             <option value="B">B</option>
             <option value="C">C</option>
             <option value="D">D</option>
             <option value="F">F</option>
            </select></td>';


    $count++;
    $count2++;
}

以下是控制器类的代码段:

$something = $this->input->post('select');
$something2 = $this->input->post('select2');
$classID = $this->input->post('classID');
$studentID = $this->input->post('studentID');
$count = 0;
$insertCount = 0;
$newEntries = array ();
$newRow = array (
    "employeeID" == $myID[0]->employeeID,
    "studentID" == $studentID[$count]->studentID,
    "type" == 'Midterm',
    "grade" == $something[$index[$count]],
    "classID" == $classID[$index[$count]]
);
die(print_r($newRow));
$newRow2 = array (
    "employeeID" == $myID[0]->employeeID,
    "studentID" == $classID[$index[$count]],
    "type" == 'Final',
    "grade" == $something2[$index[$count]],
    "classID" == $classID[$index[$count]]
);
$newEntries[$index[$insertCount]] == $newRow;
            $insertCount++;
$newEntries[$index[$insertCount]] == $newRow2;
$insertCount++;
$count++;
    }

所以问题是,对于班级和学生ID,它只将结果的最后结果传递回控制器。我现在可以忍受这个错误,但最重要的是,当这个运行时,$ something只包含值&#34; 1&#34;由die(print_r($something));

确定

1 个答案:

答案 0 :(得分:0)

要获得正确的结果,请使用标志TRUE

die(print_r($newRow, true));

print_r将返回值而不是将其打印到输出