저는 커뮤니티에서 일하고 있으며 사용자 프로필에 많은 사용자 통계를 표시하려고합니다.Codeigniter는 사용자의 통계를 표시합니다.
가장 좋은 방법은 무엇입니까?.
나는 이것을 가지고있다. 그러나 나는 그것의 최선의 방법이라고 생각하지 않는다. 그래서 나는 내 질문에 많은 통계를로드하기 위해 내가 할 수있는 것을 당신이 정말로 설명 할 수있어서 기뻐할 것이다 :
//Get the stats of a user in hes profile
function getState($username) {
//it has false so it dont try to escape the COUNT()
$this->db->select('username, firstname, lastname, freetext, imgPath, city, hood, online, level,
COUNT(forumThread.id) as totalThreads,
COUNT(forumComments.id) as totalComments
', FALSE);
$this->db->join('forumThread', 'forumThread.creater = users.username');
$this->db->join('forumComments');
$this->db->group_by('users.id');
$this->db->where('username', $username);
$statQuery = $this->db->get('users');
return $statQuery->row();
}
Codeigniter가 함수를 이스케이프 처리하지 않으므로 선택 항목의 두 번째 매개 변수를 false로 설정할 필요가 없습니다. 실제로 소스 코드는 구분 기호로 쉼표를 사용하여 문자열을 먼저 나눕니다. 그런 다음이 배열을 통해 각 항목이 필드로 간주되기 때문에 이미 존재하지 않는 경우 각 항목에 백틱을 추가합니다. 그러나 괄호가있는 곳이라면 항목을 그대로 유지합니다. –