Grouping all results in infinite scroll

     

I have a latest commented on post feature.. So when a post is commented on it jumps to the top.   I would like to know how it is possible to group all posts by their streamitem_id.in the initial call but in every call after that. so if a post matched in the 4th scroll with one in the second scroll i would like it not to show because I'd prefer it to be grouped together


I tried the GROUP by method in the below query and it just grouped items in every new scroll because its making a new call.


$query = "SELECT *   FROM streamdata m   JOIN streamdata_comments t1    WHERE";   if ($last_id!==0) {   $query .= " t1.comment_id < $last_id AND";   }   $query .= " t1.comment_streamitem=m.streamitem_id   GROUP BY m.streamitem_id   ORDER BY t1.comment_id DESC LIMIT 2";   $result = mysqli_query($mysqli $query) or die('Error: ' .    mysqli_error($mysqli));  

UPDATE  I have tried the below and getting closer to what I need. its grouping the items..but now its throwing in a random post that shouldn't even be in there.   $query = "   SELECT *   FROM streamdata_comments t1    JOIN streamdata m   ON";   if ($last_id!==0) {   $query .= " t1.comment_id < $last_id GROUP BY t1.comment_streamitem    AND";   }   $query .= "   m.streamitem_id=t1.comment_streamitem   AND t1.comment_poster=34 AND comment_type_id=1   ORDER BY t1.comment_id DESC LIMIT 2";   $result = mysqli_query($mysqli $query) or die('Error: ' .    mysqli_error($mysqli));