Yeah, so line 256 is where you set the COMMID session variable:
$_SESSION['COMMID']=$row_rsPAGES['page_1'];
your using the rsPAGES recordset which is created at line 153 - 175
you are using it to filter the Recordset4 recordset at lines 121 - 136, since it has not been set yet, it is using the value from the previous page.
you need to re order the code so that
1) the rsPAGES recordset is created
2) the COMMID session variable is set
3) the Recordset4 recordset is created.