PHP Statistics Article ranking example

Source: Internet
Author: User
Tags getdate

  This article mainly introduced the PHP statistics article ranking example, the code may use in the Dedemcs on the month, the week, the day statistics article, needs the Friend may refer to under

      Code as follows: <?php/**  *  * statistics software and articles such as month, week, day ranking  *  * $field _id (article ID)  *///Statistics month, week, The method of the day ranking require_once (DirName (__file__). /.. /include/common.inc.php "); function countdown ($field _id) {date_default_timezone_set (' Asia/shanghai ');//Set default time zone global $dsql $re _total = 1; $ TableName = ' #@__tongji '; $nowDateArray  = getdate (Time ()); $sql _tongji = "SELECT * from" $tableName ' where aid= $field _id '; $rs = $dsql->executenonequery2 ($sql _tongji); If this article information is not present, insert an if ($rs <= 0) {//Get column ID value $sql _typeid = "Select typeID from ' #@__archives ' where id= $field _id"; $t _r ow = $dsql->getone ($sql _typeid); $query = "INSERT into ' $tableName ' VALUES ($field _id, $t _row[typeid],1,1,1,1, $nowDateArray [0]);"; $dsql->execnonequery ($query); }else{  $result = $dsql->getone ($sql _tongji)   $oldTimeStamp = $result [' Lasttime '];  //Last Click Time     $m _total =       $result [' m_total '];    //Monthly click   $w _total =       $result [' W_total '];    //Week click   $d _total =       $result [' d_total '];    //Day Click     $t _total =       $result [' t_total '];    //Total Click     $oldDateArray   =  getdate ($oldTimeStamp);     //Statistics the Month if ($ nowdatearray["Year"] = = $oldDateArray ["Year"] && $nowDateArray ["mon"] = = $oldDateArray ["Mon"]) {  $m _ total++;  }else{  $m _total = 1;   }  //statistics this week $tmpStartDate = Mktime (0,0,0, $nowDateArray ["mon"], $nowDate array["Mday"], $nowDateArray ["Year"])-($nowDateArray ["wday"] * 86400);  $tmpEndDate = Mktime (23,59,59, $nowDateA rray["Mon"], $nowDateArray ["Mday"], $nowDateArray ["Year"]) + ((6-$nowDateArray ["Wday"]) * 86400);  if ($oldTimeSt AMP >= $tmpStartDate && $oldTimeStamp <= $tmpEndDate) {  $w _total++; }else{  $w _total = 1;    //Statistics today $dayStart   =mktime (0,0,0, $nowDateArray ["mon"], $nowDateArray ["Mday"], $nowDateArray [" Year "]);  //Day start timestamp $dayEnd   =mktime (23,59,59, $nowDateArray ["mon"], $nowDateArray ["Mday"], $nowDateArray ["Year"]) ; Day End Timestamp if ($oldTimeStamp >= $dayStart && $oldTimeStamp <= $dayEnd) {  $d _total++;} else{  $d _total = 1;}   $t _total++; Update STATISTICS   $DSQL->executenonequery ("Update $tableName set m_total= $m _total,w_total= $w _total,d_total= $d _total , t_total= $t _total,lasttime= $nowDateArray [0] where aid= $field _id ");   $dsql->executenonequery ("Update dede_archives set click= $t _total where id= $field _id");   $re _total = $t _total; return $re _total; }   Countdown ($aid); Method invocation  /*//MYSQL table structure   CREATE table IF not EXISTS ' Dede_tongji ' (  ' aid ' int (one) not NULL,   ' CID ' smallint (5) Not NULL,   ' tid ' smallint (5) is not NULL,   ' m_total ' int (one) not null DEFAULT ' 1 ',   ' w_total ' I NT (one) NOT null default ' 1 ',   ' d_total ' int (one) NOT null default ' 1 ',   ' t_total ' int (one) not NULL default ' 1 ',   ' lasttime ' int () not NULL,   PRIMARY KEY (' aid ')) Engine=myisam default charset=latin1; * *?>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.