如何根据级别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);
这个简单returns1,应该是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);
回声 $结果;
我正在使用 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);
这个简单returns1,应该是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); 回声 $结果;