如何根据级别 ID 获取用户计数


How to get a count of users based on level id

我正在使用zend框架,我正在尝试获取级别ID为11的用户数量。我对 Zend 很陌生,没有使用过他们的数据库查询格式。我可以在直接SQL中做到这一点,但我想保持它们的格式。任何建议都会很棒。

$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);

这只返回 1,它应该是 251

请看这个。

$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"];

更简单:

$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);

$result = $db->fetchOne($select);回声$result;