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条)

报告相同问题?

悬赏问题

  • ¥20 qt msvc qmake qtcreat
  • ¥15 c#直接使用C++ 写的class 后续
  • ¥15 为何显示keyerror fruit
  • ¥15 关于#stm32#的问题:/* User can add his own implementation to report the HAL error return state */
  • ¥15 imageware粗糙度表面
  • ¥15 python使用pulp线性优化时报错
  • ¥15 为什么我的uibot导入py模块出错呀。py文件放在了uibot里对应的python文件夹了,卸了重安也不行
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?