簡體   English   中英

如何根據級別ID獲取用戶數

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

我正在使用zend framework,並且試圖獲取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); 回聲$結果;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM