简体   繁体   English

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

[英]How to get a count of users based on level id

I am using zend framework and I am trying to get the number of users with level id of 11. I am very new to Zend and have not used their DB query format. 我正在使用zend framework,并且试图获取ID为11的用户数量。我对Zend并不陌生,还没有使用他们的数据库查询格式。 I can do it in straight SQL, but I want to keep in their format. 我可以用直接的SQL来做到这一点,但我想保持其格式。 Any suggestions would be awesome. 任何建议都很棒。

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

This simply returns 1, it should be 251 这仅返回1,应该为251

Please take a look this. 请看看这个。

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

Even simpler : 更简单:

$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 = $ db-> fetchOne($ select); echo $result; 回声$结果;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM