PHP While-Loop保持变量

I have the following PHP:

$i = 0;
$p_IDCheckBefore = $p_ID;
while ($i <= 2) {
  if($p_IDCheckAfter == $p_IDCheckBefore){
    echo "

    <div class=\"dealproductoffershop\">". htmlspecialchars($w_name) ."</div>
    <div class=\"dealproductofferline\">
      <div class=\"dealadd\">
        <button type=\"button\" class=\"btn btn-default btn-xs\">&#10010;</button>
      </div>
    </div>

    ";
  }
  $p_IDCheckAfter = $p_IDCheckBefore;
  $i++;
}

My plan is to use this while loop to check if an ID was the same in the previous row, then show some divs. But $p_IDCheckAfter keeps returning the same value as $p_IDCheckAfter.

What can I do to keep this value constant during the loop?

EDIT: values of Before and After during the loop: First loop: 26-26 & 26-26 Second loop: 26-26 & 26-26 & 26-26 Third loop: 27-27 & 27-27 etc.