【问题标题】:Passing select input array from a view to a controller (Code Igniter)将选择输入数组从视图传递到控制器(Codeigniter)
【发布时间】:2014-07-04 02:51:27
【问题描述】:

正如标题所说,我目前正在尝试将一组值从 <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 只包含由 die(print_r($something)); 确定的值“1”

【问题讨论】:

  • 我认为你应该在开始时初始化 $count=0。

标签: php arrays codeigniter select


【解决方案1】:

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

die(print_r($newRow, true));

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

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 2011-09-12
    • 2011-09-09
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多