mardi 31 août 2021

passing multiple values from input checkbox in codeigniter not working

i have a codeignter form, from where i try to pass values of multiple checkboxes and display it in another view page, the view is like:

<tbody>
  <?php
     $i=1;
    foreach($selectexcel as $val){?>
    <tr>
      <th scope="col"><input type="checkbox" id="checkItem" name="printtype[]" value="<?=$val->id?>" /></th>
      <th scope="row">
        <?= $i?>
      </th>
      <th scope="row"><?= $i?></th>
      <td><?= $val->batchnumber?></td>
    
      <td>
        <button type="submit" name="savemeda" style="margin-left:5px; font-size: 0.6em;" class="btn btn-warning">PRINT</button></td>
    </tr>
    <?php $i++; } ?>
</tbody>

below is my controller:

  public function printconsignment() {
    $data = array();
    if($this->isUserLoggedIn){
        $con = array(
            'id' => $this->session->userdata('userId')
        );

            if(isset($_POST['savemeda']))
            {
                $user_id=1;//Pass the userid here
                $checkbox = $_POST['printtype'];
                for($i=0;$i<count($checkbox);$i++){
                    $ding = $checkbox[$i];
          $data['catil'] = $this->excel_import_model->selectprint($ding);


                }}

        $this->load->model('excel_import_model');

        $this->load->view('printconsignment',$data);

        }



}

and finally my model is like below:

    public function selectprint($catil) {
                $this->db->select('*');
                $this->db->where("id", $catil);
                $this->db->from('fileupload');
             $query = $this->db->get();
             $result = $query->result();
             return $result;

    }

when i try to pass one checkbox value, its successfully passing to the next page, but when i try to select multiple checkbox, its not happening, any one value is being displayed in the next page, can anyone please tell me what is wrong here, thanks in advance




Aucun commentaire:

Enregistrer un commentaire