$s_agree_value = $s_agree_value + $vote_agree_users[$answer_id]['reputation_factor'];$vote_agree_users[$answer_id],同一个答案ID,赞同的Users不一定只有一个,这样直接以下标来获取,只能取到一个值。 再追根溯源,在answer.php里面,获取答案对应的投票的函数就已经有问题了:
if ($users = $this->fetch_all('answer_vote', "answer_id IN(" . implode(',', $answer_ids) . ") AND vote_value = 1")) { foreach ($users as $key => $val) { $data[$val['answer_id']] = $val; } }$users变量里面,可能出现多条answer_id相同的记录,比如: [0] => Array ( [voter_id] => 5 [answer_id] => 12 [answer_uid] => 5 [vote_uid] => 7 ... [1] => Array ( [voter_id] => 13 [answer_id] => 12 [answer_uid] => 5 [vote_uid] => 6 ... 此时不宜直接用map来存储数据了,否则只能存其中的一个。应该给数组再加一个维度才行。 没学过php,分析的不一对,请官方看下,谢谢。
AI智能回复搜索中,请稍后...
1 回答
public function get_vote_agree_by_answer_ids($answer_ids) { if (!is_array($answer_ids)) { return false; } array_walk_recursive($answer_ids, 'intval_string'); if ($users = $this->fetch_all('answer_vote', "answer_id IN(" . implode(',', $answer_ids) . ") AND vote_value = 1")) { foreach ($users as $key => $val) { $data[$val['answer_id']][] = $val; } } return $data; }
if ($vote_agree_users[$answer_id]) { foreach ($vote_agree_users[$answer_id] AS $key => $val) { $s_agree_value = $s_agree_value + $val['reputation_factor']; } }反对系数也一样修改,就不贴了