How can the variable $zielgr be modified within the while loop to avoid overwriting and only outputting the last value?

The issue with the current code is that the variable $zielgr is being overwritten in each iteration of the while loop, so only the last value is stored and accessible outside the loop. To avoid this, you can store each value of $zielgr in an array and then access the last value outside the loop.

$zielgr_array = array(); // Initialize an empty array to store values of $zielgr

while ($row = mysql_fetch_array($result)) {
    $zielgr = $row['zielgr'];
    $zielgr_array[] = $zielgr; // Add each value of $zielgr to the array
}

$last_zielgr = end($zielgr_array); // Get the last value of $zielgr from the array

echo $last_zielgr; // Output the last value of $zielgr