Home > php教程 > php手册 > [Additional refinement] thinkphp universal statistical function

[Additional refinement] thinkphp universal statistical function

WBOY
Release: 2016-08-08 08:50:05
Original
1275 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template