如何在搜索后保留选择的框选项。我想在选择并搜索后打印。搜索后应该在搜索之前找到。
this is my view page
<?= form_open("../Admin/getRecords"); ?>
<div class="" style="height:5.5vw;border-bottom:1.2px solid lightgrey;padding:.5%;">
<div class="col col-lg-3" style="margin-left:41%;margin-top:0%;padding-bottom: 2%;">
<label>ITR Status</label> <select name="ITRStatus" id="ITRStatus" class="form-control chosen" style="height:2.5vw;" id="sel">
<?php
// $a = $_POST['ITRStatus'];
$name = set_value('ITRStatus');
// echo '<pre>';
// print_r($name);
if(count($alldata)):
foreach($alldata as $data):
?>
<option value="<?php echo $data->id; ?><?php $name == $data->id ? "selected":""?>
?>"><?php echo $data->itr_status ?></option>
<!-- <option value="<?php //echo $record->id; ?>"><?php //echo $record->assessment_year ?>2019-20</option>-->
<?php endforeach;endif; ?>
</select>
</div>
这是我的控制器页面
public function getRecords()
{
$this->load->model('AdminModel');
$year = $this->input->post('year');
$ITRStatus = $this->input->post('ITRStatus');
$alldata = $this->AdminModel->getItrStatus();
$assessments = $this->AdminModel->getAssessmentModel();
$records = $this->AdminModel->getRecords($year,$ITRStatus);
if($records == 1 )
{
$this->itrDetail();
}
$this->load->view('SearchItr',['records' => $records,'alldata' => $alldata,'assessments' => $assessments]);
}
答案 0 :(得分:0)
您的逻辑正确,但您误认了选项标签。
<option
value="<?php echo $data->id ?>"
<?php $name == $data->id ? "selected":"" ?>
>
<?php echo $data->itr_status ?>
</option>
答案 1 :(得分:0)
好吧,我给你举个例子,怎么做
查看
<!doctype html>
<html>
<body>
<div>
<?php
if(isset($response)){
echo "<b>Name :</b> ".$response['txt_name']."<br/>";
echo "<b>Username :</b> ".$response['txt_uname']."<br/>";
echo "<b>Email :</b> ".$response['txt_email']."<br/>";
}
?>
</div>
<form method='post' action='<?php echo base_url(); ?>'>
<table>
<tr>
<td>Name</td>
<td><input type='text' name='txt_name'></td>
</tr>
<tr>
<td>Username</td>
<td><input type='text' name='txt_uname'></td>
</tr>
<tr>
<td>Email</td>
<td><input type='text' name='txt_email'></td>
</tr>
<tr>
<td> </td>
<td><input type='submit' name='submit' value='Submit'></td>
</tr>
</table>
</form>
</body>
</html>
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct() {
parent::__construct();
// load base_url
$this->load->helper('url');
}
public function index(){
$data = array();
// Check form submit or not
if($this->input->post('submit') != NULL ){
// POST data
$postData = $this->input->post();
$data['response'] = $postData;
}
// load view
$this->load->view('user_view',$data);
}
}
注意:您必须传递所需的数据才能查看,就像您想要选择的值一样,因此也必须传递才能进入视图
答案 2 :(得分:0)
更改您的查看页面代码
<?= form_open("../Admin/getRecords"); ?>
<div class="" style="height:5.5vw;border-bottom:1.2px solid lightgrey;padding:.5%;">
<div class="col col-lg-3" style="margin-left:41%;margin-top:0%;padding-bottom: 2%;">
<label>ITR Status</label>
<select name="ITRStatus" id="ITRStatus" class="form-control chosen" style="height:2.5vw;" id="sel">
<?php
$name = set_value('ITRStatus');
if(count($alldata)):
foreach($alldata as $data): ?>
<option value="<?php echo $data->id; ?>" <?php if($name == $data->id){ echo "selected"; } ?>><?php echo $data->itr_status; ?></option>
<?php endforeach;endif; ?>
</select>
</div>