The MySQL query statement on line NO. 346
The code is as follows |
Copy Code |
$sql = "Select Gid,title from". Db_prefix. "Blog WHERE hide= ' n ' and type= ' blog ' ORDER by the views DESC, Comnum DESC LIMIT 0, $num"; |
read out from Emlog_blog not hidden (hide= ' n ') and is the log (type= ' blog ', this removed the page) log, order by the viewsdesc,comnum DESC LIMIT 0, $num here $ Num set the number of bars displayed, such as 5, then in descending order of views (browse number), if the same number of views to the number of comments in order, take 5.
From the above code can be seen, the earlier the article read the number of words must be more, then lead to this popular log ranking of the article is almost unchanged. So personally I think it's a bit inappropriate.
The following to transform the code (the official interpretation of the hack program, there is a certain danger, before the operation of the backup data)
1. Hot log changed into a hot review log (to comment number as ranking, the same number of comments to browse the number of orders), as long as the exchange of views and comnum can be, the revised code is as follows:
The code is as follows |
Copy Code |
$sql = "Select Gid,title from". Db_prefix. "Blog WHERE hide= ' n ' and type= ' blog ' ORDER by Comnum DESC, views DESC LIMIT 0, $num"; |
PS: Suitable for ordinary log comments more blog, if the usual comments are less, the change is not big.
2. The popular log is changed to the hot log this month. Specify the time range for log publication in descending order, the same number of views in descending order of comments, there are 2 kinds of situations: one is this month, and one is the last 30 days.
So let's talk about this month, get the time stamp for this month's start
The code is as follows |
Copy Code |
$t = Mktime (0,0,0,date ("M", Time ()), 1,date ("Y", Time ())); The timestamp of the beginning of this month $sql = "Select Gid,title from". Db_prefix. "Blog WHERE hide= ' n ' and type= ' blogs ' and date> $t order by views DESC, Comnum DESC LIMIT 0, $num"; Complete code modified: function Gethotlog ($num) { $t = Mktime (0,0,0,date ("M", Time ()), 1,date ("Y", Time ())); $sql = "Select Gid,title from". Db_prefix. "Blog WHERE hide= ' n ' and type= ' blogs ' and date> $t order by views DESC, Comnum DESC LIMIT 0, $num"; $res = $this->db->query ($sql); $logs = Array (); while ($row = $this->db->fetch_array ($res)) { $row [' gid '] = intval ($row [' gid ']); $row [' title '] = Htmlspecialchars ($row [' title ']); $logs [] = $row; } return $logs; } |
So the last 30 days is also simple, as long as the $t that change on it.
The code is as follows |
Copy Code |
$t = time ()-3600 * 24 * 30;//last 30 days with the current access timestamp |
3. All articles are sorted in descending order by month's browsing number, sorted by number of comments in descending order of the same number of views.
Here you need to add 2 fields to the database, execute the following query statement (the database prefix defaults to emlog)
To add a field for the last browsing time:
The code is as follows |
Copy Code |
ALTER TABLE emlog_blog ADD lastview bigint () not NULL default ' 0 ' |
Add a field for this month's browse number:
The code is as follows |
Copy Code |
ALTER TABLE emlog_blog ADD monviews mediumint (8) unsigned not NULL default ' 0 ' |
After the database has been modified, the following is the modification of the log_model.php program. Line No. 289 to No. 296 increases the number of readings
Here is the total number of views and the number of views of the month browse +1, and next month Qing 0
The complete code is as follows:
[2013-05-30] Update code: Merging UPDATE statements
The code is as follows |
Copy Code |
/** * Increase the number of reading, revise the last reading time, increase the number of reading this month * * @param int $blogId */ function Updateviewcount ($blogId) { $this->db->query ("UPDATE"). Db_prefix. "Blog SET views=views+1 WHERE gid= $blogId"); $res = $this->db->query ("Select Date,lastview from". Db_prefix. "Blog WHERE gid= $blogId"); $row = $this->db->fetch_array ($res); if (Date ("M", Time ())!=date ("M", $row [' Lastview ']) && date ("M", Time ())!=date ("M", $row [' Date ']) {$this->db->query ("UPDATE"). Db_prefix. "Blog SET monviews=0,lastview=". Time ()); $this->db->query ("UPDATE"). Db_prefix. "Blog SET monviews=monviews+1,lastview=". Time (). " WHERE gid= $blogId "); } |
[2012-11-30] Code:
The code is as follows |
Copy Code |
/** * Increase the number of reading, revise the last reading time, increase the number of reading this month * * @param int $blogId */ function Updateviewcount ($blogId) { $this->db->query ("UPDATE"). Db_prefix. "Blog SET views=views+1 WHERE gid= $blogId");//total number of views per visit +1 $res = $this->db->query ("Select Date,lastview from". Db_prefix. "Blog WHERE gid= $blogId")//query log publication time and last browse time $row = $this->db->fetch_array ($res); if (Date ("M", Time ())!=date ("M", $row [' Lastview ']) && date ("M", Time ())!=date ("M", $row [' Date ')])// Determines the month of the current time and the month of the last browse time, and whether the month in which the last browse time is the same as the months of the publication time. {$this->db->query ("UPDATE"). Db_prefix. "Blog SET monviews=0")//Execute the Month browse count 0 $this->db->query ("UPDATE"). Db_prefix. "Blog Set lastview=". Time ())//Set last browse time to current } $this->db->query ("UPDATE"). Db_prefix. "Blog SET monviews=monviews+1 WHERE gid= $blogId")//Run the month browse number +1 $this->db->query ("UPDATE"). Db_prefix. "Blog SET lastview=". Time (). " where gid= $blogId ");//Update last browse time to current time } |
Change views in hot log code to Monviews
The code is as follows |
Copy Code |
$sql = "Select Gid,title from". Db_prefix. "Blog WHERE hide= ' n ' and type= ' blog ' ORDER by Monviews DESC, Comnum DESC LIMIT 0, $num"; |
PS: Finally say a few words, here is just a simple modification, there are many ways to modify the popular log arrangement.