2011-09-19 3 views
0

제 컨트롤러에서 테이블에서 정보를 가져 오기 위해 mysql 쿼리를 만드는 모델을 호출했습니다. 그것은 괜찮습니다.하지만 지금은 같은 함수 아래에서 다른 모델을 호출하고 이전 mysql 쿼리의 결과 중 하나를 기반으로 쿼리를 만들고 싶습니다. (내가 얻고 자하는 필드 이름은 "배치"입니다.) 내 컨트롤러에서 바로 값 (일괄 처리)을 가져 와서 모델로 전달한 다음 두 번째 쿼리를 만들려고 시도했지만 두 번째 모델이 컨트롤러에서 값을 가져 오지 않아 작동하지 않는 것처럼 보입니다. 친절하게 도와 주실 래요? 사전 : 여기컨트롤러에서 모델의 mysql 쿼리 결과 중 하나를 전달하는 방법은 무엇입니까?

에서 덕분에 당신은 잘 내 모델 번호 2

function batchname($batch) 
    { 
     $query1=$this->db->get_where('batch',array('batchid'=>$batch)); 

     return $query1->row_array(); 
    } 

답변

0

내 모델 번호 (1) 여기서

function student_get($id) 
    { 
     $query=$this->db->get_where('student',array('studentid'=>$id)); 


     return $query->row_array(); 

    } 

내 컨트롤러 여기

 function Get($id){ 
       $this->load->model('mod_studentprofile'); 
       $data['query']= $this->mod_studentprofile->student_get($id); 

       // To get the batch name 
       $batch= $query ['batch']; // This I get from the above query result. 

       $this->load->model('batchname'); 
       $data['query1']= $this->batchname->batchname($batch); 

       $data['tab'] = "Student Profile"; 
       $data['main_content']='studentprofile'; 
       $this->load->view('includes/template',$data); 

      } 

임 실제로 $ batch에 아무 것도 지정하지 않으면 다음과 같이 처리 할 수 ​​있습니다.

$batch= $data['query']; 

이제 변수가 전달됩니다.

$data['query1']= $this->batchname->batchname($this->mod_studentprofile->student_get($id)); 
0

당신이 첫 번째 쿼리에서 다시 값을 얻고있다 : 의존성 주입 스타일을 측면 참고로, 당신은 paramater로 전달 할 수 있으며 한 줄에 함께 할 수?

컨트롤러의 첫 번째 쿼리에서 가져 오는 값을 기록합니다.

log_message('debug', 'Batch value is '.$batch); 

또한 일부 디버그를 실행하여 실행중인 쿼리를 확인하십시오.

function batchname($batch) 
{ 
     $query1=$this->db->get_where('batch',array('batchid'=>$batch)); 
     $str = $this->db->last_query(); 
     log_message('debug', 'Batchname Query: '.$str); 
     return $query1->row_array(); 
}