The variables will cease to be once the script has finished executing - what you've got here is an exercise in maintaining state.
Your sort order links need to have all of the relevant vars encoded into the URL they send. If it's a simple <a> link you're using, gert the script to print out all the relevant variables into the link as a query string.
<?php
echo "<a href=\"list.php?sort_by=name&query=${query}&list_from=${list_from}&list_to=${list_to}\">Sort By Name</a>\n";
?>