Codeigniter - 获取Checkboxes的值并将其显示在另一页

时间:2016-01-06 04:39:16

标签: codeigniter

我是代码点火器的新手,我的问题是在我的复选框中获取所有选中的值,而我不知道如何在另一个视图中显示... < / p>

这是我的代码

查看

&#13;
&#13;
<?php foreach($sen_votes as $sen) { ?>
  <?php echo form_open("votation/balot_form"); ?>
  <div class="col-md-6">
    <center><div class="featurette panel panel-info" id="about">
  <div class="form-group">
     <div class="Form-section">
          <label class="Form-label--tick col-md-12">
           <div class="col-md-6">
             <img class="img-hov img-responsive" src="<?php echo base_url();?>webroot/assets/img/faces/face-2.jpg" id="" height ="120px" width = "120px"  />
            </div>
       <div class="col-md-6">
                                   
<input type="radio" id="" name="sen[]" class="Form-label-radio" value="<?php echo $sen['id']; ?>" onclick="myFunction()" required = "" />

                                    
 <span class="Form-label-text"></span>
 </label>  
 </div>
</div>
</div> 
                                  
 <h5 class="text text-default">
 <strong> &nbsp;Name:</strong> <?php echo $sen['fullname']; ?><br>
 <strong> &nbsp;Party Name:</strong> <?php echo $sen['party_name']; ?><br>
 <strong> &nbsp;Votes:</strong> <?php echo $sen['votes']; ?></h5>
</div>
</center>
</div>
<?php } ?>
 <div class="row">
   <div class="col-md-12">
     <div class="form-group">
       <button type="submit" class="btn btn-info btn-fill pull-right">Next <i class ="fa fa-arrow-right"></i></button>
     </div>                                 
 </div><br>
</div>
<?php echo form_close(); ?>
&#13;
&#13;
&#13;

这是我的控制器,我希望获得所有值

&#13;
&#13;
public function balot_form(){

    //Senators
       $sen_id = $this->input->post('sen_id[]');   
	   $view_sen_votes = $this->vote->view_sen($sen_id);
			
       $data = array("view_sen_votes" => $view_sen_votes);
   
	    $this->load->view("admin_dashboard/votation_page/balot_form_page", $data);


}
&#13;
&#13;
&#13;

我的模特

&#13;
&#13;
public function view_sen($sen_id){

	   $sen_id = implode(', ', $this->input->post('sen_id'));
      
      $this->db->select('*')->from('party_candidates')->where('id', $sen_id);
	
    $query = $this->db->get()->result_array();
return $query;
					
}
&#13;
&#13;
&#13;

下面是我要显示所选参议员的页面

&#13;
&#13;
<div class="col-md-6">
  <?php foreach($view_sen_votes as $sen) : ?>
   <div class="row">
     <div class="col-md-12">
       <div class="form-group">
    <label>Senators</label>
       <input type="text" class="form-control" placeholder="" value="<?php echo $sen['id']; ?>" name="sen_id[]" required="" />
                                                
         </div>        
      </div>
    <div class="col-md-6"></div>
     </div>
  <?php endforeach; ?>
</div>
&#13;
&#13;
&#13;

谢谢:)

1 个答案:

答案 0 :(得分:0)

试试这个

在控制器中

public function balot_form(){

    $sen_id[] = $_POST['sen_id'];   
    $view_sen_votes = $this->vote->view_sen($sen_id);       
    $data = array("view_sen_votes" => $view_sen_votes);
    $this->load->view("admin_dashboard/votation_page/balot_form_page", $data);
}

在模型中

public function view_sen($sen_id){

    $sen_id[] = $_POST['sen_id']; 
    foreach ($sen_id as $id => $value) {
        $this->db->select('*')->from('party_candidates')->where('id', $value);
        $query[] = $this->db->get()->result_array();
    }   
    return $query;                  
}