猿问

如何从多个复选框中检索数组值?

如何从多个复选框中检索数组值?我在检索值数组并回显该值时遇到问题。我收到这个错误


严重性:警告

消息:in_array() 期望参数 2 为数组,字符串给定

文件名:page/update.php。


拜托,你能再帮我一次吗?谢谢你。


您会找到三个文件:视图、模型和控制器。请检查我错在哪里...


更新.PHP:


<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<div class="row">

<div class="col-sm-12">

<?php echo form_open('page_controller/update_page_post'); ?>


<div class="form-group">

            <div class="row">

                <div class="col-sm-3 col-xs-12">

                    <label><?php echo trans('subcategory'); ?></label>

                </div>

           </div><div class="col-xm-12">

                         <div class="table-responsive">

                             <table class="table table-bordered table-striped" role="grid">

                            <tbody>

                                <tr>

                                <?php   $valuesub = ($page->subcat_recip_id); ?>

                            <?php   $array_of_values = explode(",", $valuesub); 

                                //if ($item['parent_id'] != "0" && $item['subcat_recip_id'] == "0") :

                    foreach ($array_of_values as $item) { 

                                        

                        if(in_array($valuesub,$item)): {  ?>


                       <td>

                           <input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>" CHECKED> &nbsp; <?php echo html_escape($item["title"]);

                                    } ?>

                                <?php   else: { ?>

<input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>"> &nbsp; <?php echo html_escape($item["title"]);

                        } 



慕尼黑8549860
浏览 162回答 2
2回答

一只名叫tom的猫

在你看来,<tr><?php&nbsp; &nbsp;$valuesub = ($page->subcat_recip_id); ?><?php&nbsp; &nbsp;$array_of_values = explode(",", $valuesub);&nbsp;foreach ($array_of_values as $item) {&nbsp;if(in_array($subcat_recip_id,$item)): {&nbsp; ?><td><input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>" CHECKED> &nbsp; <?php echo html_escape($item["title"]);} ?><?php&nbsp; &nbsp;else: { ?><input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>"> &nbsp; <?php echo html_escape($item["title"]);}&nbsp;endif;&nbsp; }?></td>&nbsp;<?php echo html_escape($valuesub); ?></tr>改成 :<tr><?php $valuesub = ($page->subcat_recip_id);$array_of_values = explode(",", $valuesub); ?><td><?php foreach ($array_of_values as $item) :?><input type="checkbox" name="subcat_recip_id[]" class="square-purple" value="<?php echo html_escape($item["title"]); ?>" <?=(in_array($subcat_recip_id,$item))?"CHECKED":""?>> &nbsp; <?=html_escape($item["title"]);?>'<?php endforeach; ?></td>&nbsp;<?=html_escape($valuesub)?></tr>在模型中:public function update($id){&nbsp;//set values$data = $this->page_model->input_values();if (empty($data["slug"])) {//slug for title$data["slug"] = str_slug($data["title"]);if (empty($data["slug"])) {$data["slug"] = "page-" . uniqid();}}$page = $this->get_page_by_id($id);&nbsp;if (!empty($page)) {$this->db->where('id', $id);return $this->db->update('pages', $data);}return false;}改成 :public function update($id){$data = $this->input_values();if (empty($data["slug"])) {&nbsp;$data["slug"] = str_slug($data["title"]);if (empty($data["slug"])) {&nbsp;$data["slug"] = "page-" . uniqid();}&nbsp;}$page = $this->get_page_by_id($id);if (!empty($page)) {$this->db->where('id', $id);return $this->db->update('pages', $data);}return false;}如果出现错误,请更新,tq
随时随地看视频慕课网APP
我要回答