使用codeigniter从post数组中获取数据

使用codeigniter从post数组中获取数据

问题描述:

I'm trying to post an array that is name="std_id[]" from view page.But in controller while trying to print the array using print_r($std_id) I can't find any data. The code is given below..

In view page:

<?php
foreach ($all_student as $v_student) {
?>
<tr><td style="display:none"><input type="text" value="<?php echo $v_student->std_id ?>" name="std_id[]"></td>
<td class="center"><?php echo $v_student->std_name; ?></td>
<?php }?>

In controller function:

$std_id = $this->input->post("std_id[]", true);
print_r($std_id);
exit();

我正在尝试发布一个 name =“std_id []” code>的数组 从视图页面。但在控制器中尝试使用 print_r($ std_id) code>打印数组时,我找不到任何数据。 代码如下所示。 p>

在视图页面中: p>

 &lt;?php 
foreach($ all_student as $ v_student){  
?&gt; 
&lt; tr&gt;&lt; td style =“display:none”&gt;&lt; input type =“text”value =“&lt;?php echo $ v_student-&gt; std_id?&gt;”  name =“std_id []”&gt;&lt; / td&gt; 
&lt; td class =“center”&gt;&lt;?php echo $ v_student-&gt; std_name;  ?&gt;&lt; / td&gt; 
&lt;?php}?&gt; 
  code>  pre> 
 
 

在控制器功能中: p>

  $ std_id = $ this-&gt; input-&gt; post(“std_id []”,true); 
print_r($ std_id); 
exit(); 
  code>  pre> 
 

You are referencing the input name wrong. You need to change the line

$std_id = $this->input->post("std_id[]", true);

With:

$std_id = $this->input->post("std_id", true);