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 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡
  • ¥20 基于MATLAB的TDOA
  • ¥15 为啥输入字体突然变了