입력 데이터를 기반으로 데이터베이스에서 데이터를 가져옵니다.
예 : 양식에서 성을 검색하면 성 데이터를 가져와야합니다. AND 또는 OR 연산자 버튼을 사용하여 모든 필드 검색에 성공했습니다.다음 레코드 검색시 데이터를 가져올 수 없습니다. 빈 필드를 나타내는 첫 번째 레코드가 표시됩니다.
그러나 단 하나의 레코드 만 얻고 있지만 검색 기준에 따라 다른 레코드를 얻지 못하는 페이지 매김 문제가 있습니다.
여기 템플릿 라이브러리를 사용하여 페이지를 포함하고 있습니다. 여기서 상기 형태 이미지
나 검색 기록을 따라 동일한 view..and 페이지 매김 링크에 표시해야 모든 필드에 텍스트를 입력함으로써 특정 레코드를 검색 할 경우에 필요한
초기 형태가 비어
모델 :
public function search_record()
{
$id= $this->input->get('id');
$name= $this->input->get('lname');
$fname= $this->input->get('fname');
$pdate= $this->input->get('pdate');
$adate= $this->input->get('adate');
$client= $this->input->get('client');
$bw= $this->input->get('bw');
$color= $this->input->get('color');
$digital= $this->input->get('digital');
$famous= $this->input->get('famous');
$place= $this->input->get('place');
$concept= $this->input->get('concept');
$thing= $this->input->get('thing');
$oldid= $this->input->get('oldid');
$note= $this->input->get('note');
// $condition = array('id_photo' =>$id);
// $condition2=array('lastname'=>$name);
// $condition3=array('firstname'=>$fname);
// $condition4=array('photo_date'=>$pdate);
//
$this->db->select('photo_id,lastname,firstname,bw,color,digital,famous,place,concept,thing,client,photo_date,add_date,note,id_photo');
$this->db->from('tblphotomstr');
$strWhere = "";
if($id != NULL){
$strWhere = "id_photo like "."'%$id%'";
}
if($name != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and lastname like "."'%$name%'";
}else{
$strWhere = "lastname like "."'%$name%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or lastname like "."'%$name%'";
}else{
$strWhere = "lastname like "."'%$name%'";
}
}
}
if($fname != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and firstname like "."'%$fname%'";
}else{
$strWhere = "firstname like "."'%$fname%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or firstname like "."'%$fname%'";
}else{
$strWhere = "firstname like "."'%$fname%'";
}
}
}
if($pdate != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and photo_date like "."'%$pdate%'";
}else{
$strWhere = "photo_date like "."'%$pdate%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or photo_date like "."'%$pdate%'";
}else{
$strWhere = "photo_date like "."'%$pdate%'";
}
}
}
if($adate != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and add_date like "."'%$adate%'";
}else{
$strWhere = "add_date like "."'%$adate%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or add_date like "."'%$adate%'";
}else{
$strWhere = "add_date like "."'%$adate%'";
}
}
}
if($client != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$client%'";
}else{
$strWhere = "client like "."'%$client%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$client%'";
}else{
$strWhere = "client like "."'%$client%'";
}
}
}
if($bw != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$bw%'";
}else{
$strWhere = "client like "."'%$bw%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$bw%'";
}else{
$strWhere = "client like "."'%$bw%'";
}
}
}
if($color != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$color%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$color%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
}
if($digital != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$digital%'";
}
}
}
if($famous != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$famous%'";
}else{
$strWhere = "client like "."'%$famous%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$digital%'";
}
}
}
if($place != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$place%'";
}else{
$strWhere = "client like "."'%$place%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$place%'";
}else{
$strWhere = "client like "."'%$place%'";
}
}
}
if($concept != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$concept%'";
}else{
$strWhere = "client like "."'%$concept%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$concept%'";
}else{
$strWhere = "client like "."'%$concept%'";
}
}
}
if($thing != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$thing%'";
}else{
$strWhere = "client like "."'%$thing%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$thing%'";
}else{
$strWhere = "client like "."'%$thing%'";
}
}
}
if($oldid != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$oldid%'";
}else{
$strWhere = "client like "."'%$oldid%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$oldid%'";
}else{
$strWhere = "client like "."'%$oldid%'";
}
}
}
if($note != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and note like "."'%$note%'";
}else{
$strWhere = "note like "."'%$note%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or note like "."'%$note%'";
}else{
$strWhere = "note like "."'%$note%'";
}
}
}
컨트롤러 :
public function search()
{
print_r($this->search_model->search_record());
$limit = 1;
$config["base_url"] = base_url('Home/search');
$config['total_rows'] = $this->db->count_all('tblphotomstr');
$config["per_page"] = $limit;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['cur_tag_open'] = ' <li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$offset = 0;
if (!empty($_GET['per_page'])) {
$pageNo = $_GET['per_page'];
$offset = ($pageNo - 1) * $limit;
}
$data = array();
$this->db->limit($limit, $offset);
$data['records']= $this->search_model->search_record();
print_r($data);
$this->template->set('title', 'Edit Record');
$this->template->load('default_layout', 'contents' , 'search', $data);
}
PLS는 전체 모델 코드와 매김 코드를 게시 도움이되기를 바랍니다 - 내가 모두를 생각하기 때문에 get 매개 변수가 2 페이지 또는 그와 비슷한 것을 클릭 한 다음에 길을 잃는 중입니다 ... 또 다른 추천 - querybuilder를 올바르게 사용해야합니다. 전체 쿼리가 완전히 안전하지 않습니다. – sintakonte
보기에서 i가 사용되었습니다 (
일부 설명과 함께 양식 이미지로 @ sintakonte 내 쿼리를 업데이 트 ... 분명하지 pls 가이드 .. –