php 从 Codeigniter 中的多个选择框中获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13025253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:40:27  来源:igfitidea点击:

Get Values from Multiple select Box In Codeigniter

phpcodeigniterselect

提问by Harshal Mahajan

I have a multiple select box:

我有一个多选框:

<select name="tar[]" multiple="multiple" style="height:100px;" id="select1">
            <?php foreach($lists as $list){ ?>
            <option value="<?php echo $list['des_id']; ?>"><?php echo $list['designation']; ?></option>
            <?php } ?>

            </select>

At controller i am trying to get the values of selected fields,but failed to get that and i am getting values like 2 or 3.

在控制器上,我试图获取所选字段的值,但未能获取,我得到了 2 或 3 之类的值。

$target = $this->input->post('tar');
                  print_r($target);die;

Am i doing right??please guide me.Thanks.

我做得对吗??请指导我。谢谢。

采纳答案by Harshal Mahajan

okay i got the answer...

好吧,我得到了答案……

here is i am wrong,just i have to define the array in controller:

这是我错了,只是我必须在控制器中定义数组:

$target['tar'] = $this->input->post('tar');
print_r($target);die;

回答by Svetoslav

I am not sure but try this to get all tars

我不确定,但试试这个来得到所有的焦油

foreach($this->input->post("tar") as $tar){
    echo $tar;
}

回答by uniquecode1

You can also use Core PHP style,because Core PHP is the top of all framework:

你也可以使用 Core PHP 风格,因为 Core PHP 是所有框架的顶部:

if(isset($_POST['tar'])){
foreach ($_POST['tar'] as $tar_value){
        print "You are selected $tar_value<br/>";
        }
}