zhangjingyu
“zhangjingyu第9行,从pw_threads表里查询当前主题的收藏数favors,这个没毛病;
第10行,从pw_elements表里按收藏数(value,不同表的字段名可能不一样)升序排列查询类型为收藏排行(hotfavor)的数据,筛选出value和eid。这个查询有什么意义呢?
第12行,如果当前主题的收藏数大于收藏排 .. (2018-08-12 06:55) 查看本帖”(引用内容)对照42楼的代码及43楼我的理解看修改,就能明白了。
function hotfavorUpdate($tid, $fid) {
if (!($this->ifcache & 1024) || !$tid || !$fid) {
return false;
}
$eid = $this->db->get_value("SELECT eid FROM pw_elements WHERE type='hotfavor' AND mark=" . S::sqlEscape($fid) . " AND id=" . S::sqlEscape($tid));
if ($eid) {
$this->db->update("UPDATE pw_elements SET value=value+1 WHERE eid=" . S::sqlEscape($eid));
} else {
$rt = $this->db->get_one("SELECT favors FROM pw_threads WHERE tid=" . S::sqlEscape($tid));
//$rs = $this->db->get_one("SELECT value,eid FROM pw_elements WHERE type='hotfavor' ORDER BY value ASC");
if ($rt['favors'] > 0) {//$rs['value']
//$this->db->update("DELETE FROM pw_elements WHERE eid=" . S::sqlEscape($rs['eid']));
$favors = array(
'id' => $tid,
'mark' => $fid,
'value' => $rt['favors'],
'type' => 'hotfavor'
);
$this->db->update("REPLACE INTO pw_elements SET" . S::sqlSingle($favors, false));
}
}
return true;
}