duanmei1536 2017-05-10 06:41
浏览 39

从codeigniter中的foreach中的输入文本中获取值

I have a question about how to get value from input text within foreach(), when I execute the code it gets the last row of data inside table.

Here is the view code:

<?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 ++;
}
?>

How can I get the checked row and input from the table when submit is clicked?

  • 写回答

3条回答 默认 最新

  • douren7921 2017-05-10 06:45
    关注

    You have to make some change in your code like:

    <center><input type="checkbox" name="approvechk">
    

    the above checkbox statement resides insides a foreach() loop, so you have to change its name like:

    <center><input type="checkbox" name="approvechk[]">
    

    here approvechk[] is used so that it can hold multiple values in it.

    After that, entire input elements are not wrapped inside a form tag, so this cannot be submitted directly to server. So either wrap then in a <form> tag or use jquery to submit the user data to server.

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助