dttphb59319 2017-04-18 04:36
浏览 45
已采纳

如何在codeigniter中获取值数组?

How to get value post array in codeigniter? I have problem when I get value post array and echo the value. How to show post value when submit? here the error message:

A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: controllers/blablabla

view html:

<?php $i=0; foreach ($doc as $row) { ?>
<label>
<input name="size[<?php echo $i; ?>]" type="checkbox" value="<?php echo $row['doc']; ?>">&nbsp;&nbsp;<?php echo $row['doc']; ?>
</label>
<?php $i++; } ?>

controller :

$size = $this->input->post('size');
for ($i=0; $i<count($doc); $i++) 
{
   echo $size[$i];
}
  • 写回答

3条回答 默认 最新

  • dongqiang5865 2017-04-18 05:03
    关注

    Change the way name of checkbox written as follows,

    <?php foreach ($doc as $row) { ?>
    <label>
      <input name="size[]" type="checkbox" value="<?php echo $row['doc']; ?
      >">&nbsp;&nbsp;<?php echo $row['doc']; ?>
    </label>
    <?php } ?>
    

    And in post method,

    $size_arr = $this->input->post('size');
    foreach($size_arr as $v){
      echo $v;
    }
    

    if for some reason it is not working then check with,

    $size_arr = $_POST['size'];
    foreach($size_arr as $v){
      echo $v;
    }
    

    EDIT

    One more alternative,

    $arr = $this->input->post();
    $size_arr = $arr['size'];
    foreach($size_arr as $v){
      echo $v;
    }
    

    Core version,

    $arr = $_POST;
    $size_arr = $arr['size'];
    foreach($size_arr as $v){
      echo $v;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码求涡量
  • ¥100 采用栈和深度优先算法对我的代码进行修改显示路径
  • ¥15 pointnet2包安装
  • ¥20 射频功率问题,解答者有酬谢!
  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00
  • ¥15 odbc代码新增sqlserver数据源