diff --git a/mod/forum/rate.php b/mod/forum/rate.php index d3ae2bd7e5d..990f5c6c7a4 100644 --- a/mod/forum/rate.php +++ b/mod/forum/rate.php @@ -29,11 +29,15 @@ if ($data) { + $lastpostid = 0; + foreach ((array)$data as $postid => $rating) { if ($postid == "id") { continue; } + $lastpostid = $postid; + if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $postid)) { if ($rating != $oldrating->rating) { $oldrating->rating = $rating; @@ -54,7 +58,7 @@ } } } - if ($post = get_record('forum_posts', 'id', $postid)) { + if ($post = get_record('forum_posts', 'id', $lastpostid)) { // To find discussion we're in if ($returntoview and ($discussion = get_record('forum_discussions', 'id', $post->discussion))) { redirect("$CFG->wwwroot/mod/forum/view.php?f=$discussion->forum", get_string("ratingssaved", "forum")); } else {