我能够在我的 FirstView.php 上循环获取数据。除获取的数据外,循环中还有$i
值和单选按钮值。因此,当用户选择单选按钮并提交表单时,我希望将单选按钮的值和$i
传递给 SecondView.php 以显示已选择的服务。但是,我只能在我的 SecondView.php 上显示的循环中获取最后一个值。
FirstView.php
<?php echo validation_errors(); ?>
<?php echo form_open('Bookings/Booking'); ?>
<table class='table table-hover'>
<thead class='thead-light'>
<tr>
<th scope='col'></th>
<th scope='col'>Options Without Possessions</th>
<th scope='col'></th>
<th scope='col'></th>
<th scope='col'></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
foreach ($quotes_fetched as $row_quotes_fetched) {
echo "
<tr>
<th scope='row'>$i <input type='hidden' name='test' id='test' value='".$i."'size='1'/></th>
<td>".$row_quotes_fetched->ori."</td>
<td>". $row_quotes_fetched->dest ."</td>
<td>$". round($row_quotes_fetched->sellcost, 2)."</td>
<td><input type='radio' name='Bk_Option' id='Bk_Option_0' class = 'Bk_OptionSel' value='$row_quotes_fetched->sellcost' required /></td>
</tr>"; $i++;}?>
<thead class='thead-light'>
<tr>
<th scope='col'></th>
<th scope='col'>Options With Possessions</th>
<th scope='col'></th>
<th scope='col'></th>
<th scope='col'></th>
</tr>
</thead>
控制器(Booking.php)
public function Booking(){
$this->form_validation->set_rules('Bk_Option', 'Pleae select one option','required');
$service = $this->input->post('Bk_Option');
$this->session->set_userdata('service_selected', $service);
$hiddentext = $this->input->post('test');
$this->session->set_userdata('selTest', $hiddentext);
$data['Cont'] = $this->session->userdata('selTest');
$qid = $this->session->userdata('qid');
$this->load->view('SecondView'. $data);
}
SecondView.php
<?php echo 'Service Selected: '.$Cont ?>
结果:
例如,在FirstView.php上获取了 4行,然后选择第二行以及 $i = 2
的值和< strong> radio button = 200
,然后单击提交,它将显示单选按钮的正确值,但显示为 $i is 4
的值。
答案 0 :(得分:0)