2015-01-07 2 views
0

젠드 프레임 워크를 사용하고 있으며 레벨 ID가 11 인 사용자 수를 얻으려고합니다. 젠드에 매우 익숙하며 DB 쿼리 형식을 사용하지 않았습니다. 나는 그것을 직선적 인 SQL로 할 수 있지만, 나는 그들의 형식을 유지하고 싶다. 어떤 제안이 굉장 할 것입니다.레벨 ID를 기반으로 사용자 수를 얻는 방법

$select = $table->select() 
    ->setIntegrityCheck(false) 
    ->from(array('u' => $table->info('name')), array('cnt' => 'COUNT(u.user_id)')) 
    ->where('level_id = ?', 11) 
    ->where('approved = ?', 1) 
    ->where('verified = ?', 1) 
    ->where('enabled = ?', 1); 

이 단순히

답변

0

(251)보고이를하시기 바랍니다해야, 1 반환합니다.

$select = $db->select() 
    ->setIntegrityCheck(false) 
    ->from($table->info('name'), array('ctn'=>'COUNT(user_id)')) 
    ->where('level_id = ?', 11) 
    ->where('approved = ?', 1) 
    ->where('verified = ?', 1) 
    ->where('enabled = ?', 1); 

$result = $db->fetchRow($select); 
echo $result["ctn"]; 
0

더 간단 :

$select = $db->select() 
->setIntegrityCheck(false) //really necessary ? 
->from($table->info('name'), 'COUNT(user_id)') 
->where('level_id = ?', 11) 
->where('approved = ?', 1) 
->where('verified = ?', 1) 
->where('enabled = ?', 1); 

$의 원인이 = $ DB-> 대하여 fetchone ($ 선택); echo $ result;

관련 문제