亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類別與每個類別的兼容性,帶有代碼符號中的復選框

類別與每個類別的兼容性,帶有代碼符號中的復選框

PHP
SMILET 2022-09-03 15:51:57
我有一類化學品,需要檢查每類化學品與自我和他人的兼容性。帶有復選框的循環內的循環。1. 無法通過javascript點擊隱藏元素時設置值;2.我如何繼續和優化,因為24個類別的數據高達14000 +奇數條目。3. 建議使用逗號分隔值或單個條目?4. 如何編輯記錄并保持復選框選中時從同一頁面上的數據庫表中提取數據代碼如下:控制器public function compactibility_chart_master(){    $data['title'] = 'Compactibility Chart Master';    $this->form_validation->set_rules('category[]', 'Category Name','required|trim|xss_clean');    if($this->form_validation->run() === FALSE){        $data['category'] = $this->admin_model->get_all_active_entities('tbl_category');        $this->load->view('admin/compactibility_chart_master',$data);    }else{        $this->admin_model->set_compactibility_chart_master();        $this->session->set_flashdata('success','Compacitibiliy Chart Master updated Successfully');        redirect('compactibility_chart_master', 'refresh');    }}型public function set_compactibility_chart_master(){    $post = $this->_array_remove_null($this->input->post());    $insertdata = array();    for($z=0;$z<count($post['cat_cat']);$z++){        foreach($post['cat_cat'] as $values){            $insertdata[] = array(                'category'          => $post['category'][$z],                'category_compact'  => $values,            );        }    }    $this->db->insert_batch('tbl_compactibility_master',$insertdata);    return true;}視圖<form name="compatibility_form" id="compatibility_form" method="post"  enctype="multipart/form-data" data-parsley-validate>    <table class="table table-bordered" width="100%">        <?php if(!empty($category)){ foreach($category as $cat_results){ ?>        <tr class="data">            <th>                <button class="btn btn-primary btn-sm my-2" type="button"><?=$cat_results->category_name;?></button>                <input type="hidden" name="category[]" class="categooryclass" value="<?=$cat_results->id;?>">            </th>                           
查看完整描述

2 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

將復選框值存儲在具有唯一ID的單獨表中,將復選框中的id值設置為值,并將字段名稱顯示為標簽

因為將來在某些情況下必須更改復選框名稱,以便可以輕松更改該特定 ID 行數據。當您嘗試使用逗號分隔符保存時,這是不可能的。


查看完整回答
反對 回復 2022-09-03
?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

在這里,我找到了一種方法來做到這一點。希望它能幫助別人。謝謝


控制器


public function compactibility_chart_master(){

    $data['title'] = 'Compactibility Chart Master';

    $this->form_validation->set_rules('category[]', 'Category Name','required|trim|xss_clean');

    if($this->form_validation->run() === FALSE){

        $data['category'] = $this->admin_model->get_all_active_entities('tbl_category');

        $this->load->view('admin/compactibility_chart_master',$data);

    }else{

        $this->admin_model->set_compactibility_chart_master();

        $this->session->set_flashdata('success','Compacitibiliy Chart Master updated Successfully');

        redirect('compactibility_chart_master', 'refresh');

    }

}


public function set_compactibility_chart_master(){

    $post = $this->input->post();

    for($z=0;$z<count($post['category']);$z++){

        $sub_cat = "";

        foreach($this->input->post('catcat'. $z) as $values){

            $sub_cat .= $values.",";

        }

        $exp = explode(",",$sub_cat);

        $newexp = array_unique($exp);

        $newexp = implode($newexp, ',');

        $insertdata = array(

            'category'          => $post['category'][$z],

            'category_compact'  => $newexp,

        );

        $this->db->where('category',$post['category'][$z]);

        $exist = $this->db->get('tbl_compactibility_master');

        $exist = $exist->num_rows();

        if($exist == 0){

            $this->db->insert('tbl_compactibility_master',$insertdata);

        }else{

            $this->db->where('category',$post['category'][$z]);

            $this->db->update('tbl_compactibility_master',$insertdata);

        }

    }

    return true;

}

視圖


<form name="compatibility_form" id="compatibility_form" method="post"  enctype="multipart/form-data" data-parsley-validate>

    <table class="table table-bordered" width="100%">

        <?php $cc=0; foreach($category as $cat_results){ ?>

        <tr class="data">

            <th>

                <button class="btn btn-primary btn-sm my-2" type="button"><?=$cat_results->category_name;?></button>

                <input type="hidden" name="category[]" class="categooryclass" value="<?=$cat_results->id;?>">

            </th>                           

            <td>

            <div class="row">

                <?php foreach($category as $key => $cat_res){ $get_single = $this->admin_model->get_single_record_compactibility($cat_results->id);?>

                <div class="col-md-6">

                    <div class="form-check-inline">

                        <label class="form-check-label">

                        <input type="checkbox" class="form-check-input my-2 checkedme" name="catcat<?=$cc;?>[]" value="<?=$cat_res->id;?>" <?php if($cat_results->id == $cat_res->id){ ?> checked="checked" <?php } ?> <?php if(in_array($cat_res->id,$get_single)){ ?>checked="checked"<?php } ?> data-forcheck="<?=$cat_results->id;?>">

                         <label class="form-check-label"><?=$cat_res->category_name;?></label>

                    </div>

                </div>

                <?php } ?>

              </div>

           </td>

       </tr>

       <?php $cc++; } ?>

   </table>

   <div class="row">

       <div class="col-md-4">

           <div class="form-group">

              <button class="btn btn-primary btn-sm my-4" id="submit_button" type="submit">Save Data</button>

            </div>

        </div>

    </div>

</form>

函數 get_single_record_compactibility()


public function get_single_record_compactibility($cat){

    $this->db->where('category',$cat);

    $result = $this->db->get('tbl_compactibility_master');

    $result = $result->row();

    if(!empty($result)){

        return explode(",",$result->category_compact);

    }else{

        return array();

    }

}

腳本


$('.checkedme').on("click",function() {

    var getVal = $(this).val();

    var test = $(this).data('forcheck');

    $('#company_form').find("input[data-forcheck='"+getVal+"'][value='"+test+"']").prop('checked',this.checked);

});


查看完整回答
反對 回復 2022-09-03
  • 2 回答
  • 0 關注
  • 100 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號