查询时,保留输入的查询内容,(以及默认选中某个下拉列表

思路:将输入的内容或选项提交给控制层,并把值赋给显示层,在显示时把默认value值输出、option默认选中。

 查询时,保留输入的查询内容,(以及默认选中某个下拉列表_第1张图片

1、控制层:

		function searchinfo(){


			$name = $this->input->post('name');            
			$mobile =trim($this->input->post('mobile'));			
			$workplace = trim($this->input->post('workplace'));
			$begindate = trim($this->input->post('begindate'));
			$comfrom =trim($this->input->post('comfrom'));
			$lifecity =trim($this->input->post('lifecity'));


			
			$data['name'] = $name;
			$data['mobile'] = $mobile;
			$data['workplace'] = $workplace;
			$data['begindate'] = $begindate;
			$data['comfrom'] = $comfrom;
			$data['lifecity'] = $lifecity;
			
			$this->load->model('student_model');
			$data['query'] = $this->student_model->search_student();
			

			$data['query2'] = $this->student_model->get_studentinfo();
			$data['query3'] = $this->student_model->get_lifecity();
			$data['query4'] = $this->student_model->get_comefrom();


         

			if($data['query'] == NULL){
				$this->load->view('header');
				$this->load->view('student_search2',$data);
				$this->load->view('footer');
			}else{
				$this->load->view('header');
				$this->load->view('student_search',$data);
				$this->load->view('footer');
			}
}


2、显示层

<?php 
							$option ="<option value =''>-请选择-</option>";
							$select='';
						<span style="color:#FF0000;"> foreach ($query2 as $v){							 
						 	
						 
													 
						 	if($v['begindate'] == $begindate){
							
						 		$select="selected='selected'";

						 	}
							
						      $option = $option."<option value =".$v['begindate']." ".$select.">".$v['begindate'].'</option>';
						      $select = '';
						 	
						 }</span>
						?>


3、另一实例


<span style="font-size:18px;">//得到符合队伍条件的团体比赛项目
			public function getteameventList($matchid,$intna,$intnv,$minage){
				//已报项目,默认为选中状态。			
				//查询已报项目
				$teamid = $_SESSION['teamid'];
				$sql = "select *from teamform where teamID = '$teamid' ";
				
				$query = $this->db->query($sql);
				$rowdata = $query->row_array();
				if($rowdata!=null){

					$checkone = $rowdata["eventID"];
					
				}else{
					$checkone ="";
				}
				
				//进行循环判断已报项目是否与下拉选项中某个选项值一样。
				
				$sql = "select eventid,eventname from events where matchid = ".$matchid." and maxna >= ".$intna." and minna <= ".$intna." and maxnv >= ".$intnv." and minnv <= ".$intnv." and minage >=".$minage;
				//echo $sql;
				$query = $this->db->query($sql);
				$arrdata = $query->result_array();
				$stroption = "";
				$select = '';

				$i = 0;
				if($arrdata){
					<span style="color:#FF0000;">foreach($arrdata as $value){</span>
<span style="color:#FF0000;">						
						if($arrdata[$i]["eventid"] == $checkone ){
							$select="selected='selected'"; 
						}
						$stroption = $stroption."<option value=\"".$value['eventid']."\"".$select.">".$value['eventname']." </option>";
						$select = '';
						$i=$i+1;
					}</span>
				}
				
				
				
				return $stroption;
			}</span>



你可能感兴趣的:(查询时,保留输入的查询内容,(以及默认选中某个下拉列表)