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. I can do it in straight SQL, but I want to keep in their format. 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
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); echo $result;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.