2014-10-07 2 views
0

나는 각 사용자의 모든 후보자 수를 표시하려고 시도하고있다. 그러나 총합계 만 표시하고있다. 후보자를 업로드 한 각 사용자의 개별 수를 표시한다.이 문제를 해결하는 데 도움이된다. .. 난 내가 정확한 쿼리 싶은 말은 ... 미리 감사는 다음은 사용자 컨트롤러나는 개인 수를 원한다 codeigniter에있는 각 사용자

입니다

사용자 컨트롤러 :

function GetCandidate($options = array()) { 
    if(isset($options['candidateId'])) 
    $this->db->where('candidateId',$options['candidateId']); 

    if(isset($options['userId'])) 
     $this->db->where('canUserId',$options['userId']); 

    if(isset($options['userBranch'])) 
     $this->db->where('canUserBranch',$options['userBranch']); 

    if(isset($options['candidateFname'])) 
    $this->db->where('candidateFname',$options['candidateFname']); 

    if(isset($options['candidateMname'])) 
    $this->db->where('candidateMname',$options['candidateMname']); 

    if(isset($options['candidateLname'])) 
    $this->db->where('candidateLname',$options['candidateLname']); 

    if(isset($options['candClient'])) 
    $this->db->where('candClient',$options['candClient']); 

    if(isset($options['candRequirement'])) 
    $this->db->where('candRequirement',$options['candRequirement']); 


    if(isset($options['activateddate'])) 
    $this->db->where('activateddate',$options['activateddate']); 

    if(isset($options['limit']) && isset($options['offset'])) 
    $this->db->limit($options['limit'], $options['offset']); 
    else if(isset($options['limit'])) 
    $this->db->limit($options['limit']); 

    if(isset($options['join'])){ 
    $this->db->select('can . * ,c.clientName,r.requirementName,r.designation,u.userName,u.userMName,u.userLName'); 
    $this->db->from('candidates as can'); 
    $this->db->join('clients as c','can.candClient=c.clientId '); 
    $this->db->join('requirement as r','r.requirementId=can.candRequirement'); 
    $this->db->join('users as u','can.canUserId=u.userId '); 
    $this->db->order_by("candidateId", "desc"); 
    $query = $this->db->get(); 

    if(@$options['candidateId']) return $query->row(0); 
    return $query->result(); 
    } 
    $this->db->order_by("candidateId", "desc"); 

    $query = $this->db->get('candidates'); 

    if(isset($options['count'])) return $query->num_rows(); 

    if(@$options['candidateId']) return $query->row(0); 

    return $query->result(); 

} 

사용자보기 : 후보의

function manage(){ 
    $userId = $this->phpsession->get("userId"); 
    $userType = $this->phpsession->get('userType'); 
    $date = date("Y-m-d"); 
    if(!$userId && !$this->phpsession->get("userType")){ 
    redirect(base_url()); 
} 

$options['join'] = true; 
$data['users'] = $this->user_model->GetUser($options); 
$data['totalprofile'] = $this->candidate_model->GetCandidate(array("count"=>true)); 
$data['page_title']="User Details"; 

$this->layout->view("user/manage",$data); 
} 

모델 :

<th style="width: 5px">UID</th>  
<td><?php echo $totalprofile; ?>  

답변

0
$this->db->order_by("candidateId", "desc"); 
    // Add a Where condition to get results only for selected user 
    $this->db->where('UserId', XXXXX); 
$query = $this->db->get('candidates'); 

조건은 다음과 코드가 유용 할 수 있습니다 그 사용자

0

의 행을 초래할해야하는 위치에 추가. 필자는 전체 코드를 작성하지 않았으며 필요한 코드 만 작성했습니다. 컨트롤러

코드 -

당신이 "인 getUser"기능에 대한 코드를 작성하지 않은 것처럼
function manage(){ 
    $options['join'] = true; 
    $data['users'] = $this->user_model->GetUser($options); 
    $data['totalprofile'] = $this->candidate_model->GetCandidate(array("count"=>true)); 
} 

, 나는 몇 가지의 배열이 있다고 가정하고있다. $ options에 저장합니다. 모델

코드 - 뷰에서

function GetCandidate($options){ 
    $can = array(); 
    foreach($options as $key => $value){ 
    $conditions = array('canUserId'=>$value['userId'], 'canUserBranch'=> $value['userBranch']); // put the array of conditions 
    $this->db->select('*'); 
    $this->db->from('candidates'); 
    $this->db->where(array('', $conditions)); 
    $can[$value['userId']] = $this->db->get()->num_rows(); // use userId as key here as you will be able to access the count array element in view page using this keys 
    } 
    return $can; 
} 

코드 -

foreach($users as $key => $value){ 
    echo "User Id: "$value['userId'].", Candidate Count per user: ". $totalprofile[$value['userId']]; 
} 

그냥 위의 코드를 사용하고 내가 귀하의 의견을 알려주세요.

관련 문제