Php 从codeigniter中foreach内的输入文本中获取值
我有一个问题,关于如何从Php 从codeigniter中foreach内的输入文本中获取值,php,codeigniter,Php,Codeigniter,我有一个问题,关于如何从foreach()中的输入文本中获取值,当我执行代码时,它会获取表中的最后一行数据 以下是查看代码: <?php $count = 1; foreach ($data as $row) {?> <thead> <th>No</th> <th>Out ID</th> <th>Name</th> <th>Dorm</th> <t
foreach()
中的输入文本中获取值,当我执行代码时,它会获取表中的最后一行数据
以下是查看代码:
<?php
$count = 1;
foreach ($data as $row) {?>
<thead>
<th>No</th>
<th>Out ID</th>
<th>Name</th>
<th>Dorm</th>
<th>Date</th>
<th>Approve</th>
<th>Comment</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td><center><?php echo $count; ?> </td>
<td><center><?php echo $row->IdOut; ?> </td>
<td><center><?php echo $row->Name; ?> </td>
<td><center><?php echo $row->Dorm; ?> </td>
<td><center><?php echo $row->Date; ?> </td>
<td><center><input type="checkbox" name="approvechk"></td>
<td><center><input type="text" name="aproverComment"></td>
<td><center><input type="submit" name="submit" value"submit"></td>
</tr>
</tbody>
<?php $count ++;
}
?>
不
外标识
名称
宿舍
日期
批准
评论
行动
单击“提交”时,如何从表中获取选中行和输入?您必须对代码进行一些更改,如:
<center><input type="checkbox" name="approvechk">
此处使用了approvechk[]
,因此它可以在其中保存多个值
之后,整个输入元素不会包装在表单标记中,所以不能直接提交给服务器。因此,要么用
标记包装,要么使用jquery将用户数据提交到服务器。下面的代码可以工作,但如果您看看哪个代码更适合处理表中的数据就更好了
<?php
$count = 1;
foreach ($data as $row) {?>
<thead>
<th>No</th>
<th>Out ID</th>
<th>Name</th>
<th>Dorm</th>
<th>Date</th>
<th>Approve</th>
<th>Comment</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td><center><?php echo $count; ?> </td>
<td><center><?php echo $row->IdOut; ?> </td>
<td><center><?php echo $row->Name; ?> </td>
<td><center><?php echo $row->Dorm; ?> </td>
<td><center><?php echo $row->Date; ?> </td>
<form type="post">
<td><center><input type="checkbox" name="approvechk"></td>
<td><center><input type="text" name="aproverComment"></td>
<td><center><input type="submit" name="submit" value"submit"></td>
</form>
</tr>
</tbody>
<?php $count ++;
}
?>
不
外标识
名称
宿舍
日期
批准
评论
行动
不
外标识
名称
宿舍
日期
批准
评论
行动
感谢您的回复,当我单击“提交”时,我如何在控制器中获取所选行?对不起,我忘记了放置表单标记,在我这样做之后,我是正常还是正常地获取输入文本?例如,在控制器中提交时,如何获取输入文本和选中字段?我只是像$this->input->post('approvechk[])那样得到它吗;和$this->input->post('approverComment');或者怎么做?感谢编辑@SiHa,抱歉英语不好(仍在学习:D)感谢回复,我如何从控制器获得输入和检查?
<?php
$count = 1;
foreach ($data as $row) {?>
<thead>
<th>No</th>
<th>Out ID</th>
<th>Name</th>
<th>Dorm</th>
<th>Date</th>
<th>Approve</th>
<th>Comment</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td><center><?php echo $count; ?> </td>
<td><center><?php echo $row->IdOut; ?> </td>
<td><center><?php echo $row->Name; ?> </td>
<td><center><?php echo $row->Dorm; ?> </td>
<td><center><?php echo $row->Date; ?> </td>
<form type="post">
<td><center><input type="checkbox" name="approvechk"></td>
<td><center><input type="text" name="aproverComment"></td>
<td><center><input type="submit" name="submit" value"submit"></td>
</form>
</tr>
</tbody>
<?php $count ++;
}
?>
<thead>
<th>No</th>
<th>Out ID</th>
<th>Name</th>
<th>Dorm</th>
<th>Date</th>
<th>Approve</th>
<th>Comment</th>
<th>Action</th>
</thead>
<tbody>
<?php
$count = 1;
foreach ($data as $row) { ?>
<tr>
<td><center><?php echo $count; ?> </td>
<td><center><?php echo $row->IdOut; ?> </td>
<td><center><?php echo $row->Name; ?> </td>
<td><center><?php echo $row->Dorm; ?> </td>
<td><center><?php echo $row->Date; ?> </td>
<td><center><input type="checkbox" name="approvechk"></td>
<td><center><input type="text" name="aproverComment"></td>
<td><center><input type="submit" name="submit" value"submit"></td>
</tr>
<?php $count ++;
}?
</tbody>