This function can directly count the total number of users, total number of articles, total clicks on articles, etc.
This function only supports versions below thinkphp V5. Please bypass /**<br>
*ThinkPHP Universal Statistics v1.1 (Author: Xiao Zeng)<br>
* @param $table Database table name<br>
* @param $where query conditions support string or array<br>
* @param $field View field The incoming field will count the total value of this field<br>
* @return Return number No result returns 0<br>
*/<br> when using V5 version.
function get_count($table,$where="",$field=""){<br>
$db = M($table);<br>
If($field){<br>
$count = $db->where($where)->sum($field);<br>
}else{<br>
$count = $db->where($where)->count();<br>
}<br>
Return $count ? $count : 0;<br>
}<br>
<br>
<br>
//Usage example <br>
<br>
//Count the total number of users<br>
get_count('user');<br>
<br>
//Statistics on the number of VIP users<br>
get_count('user','vip=1'); or get_count('user',array('vip'=>1));<br>
<br>
//Statistics on the total number of clicks on articles<br>
get_count('article','','click');<br>
<br>
//Count the number of unreviewed articles<br>
get_count('article','audit=0'); or get_count('article',array('audit'=>0));<br>
<br>
<br>
//Can also be used in templates<br>
<br>
Existing members of this book: <b>{:get_count('user')}</b> people <br>
<br>
<br>
//Communication QQ group 324098841<br>
//Forum http://www.flash127.com