I need to prevent the assigned filter from being lost when paging, modifying, deleting and / or searching for records. This is one of the 3 input I have assigned to a table in sql, all three share the $result
.
How do I add the variable $SESSION
to this exercise?
<form action="" method="GET">
Filtrar por región:
<select name="examen1">
<option>Elija una región ...</option>
<option value="15">XV Región de Arica y Parinacota</option>
<option value="1" <?php if(isset($_POST['region']) and $_POST['region'] == 1):?> selected <?php endif;?>>I Región de Tarapacá</option>
<option value="2" <?php if(isset($_POST['region']) and $_POST['region'] == 2):?> selected <?php endif;?>>II Región de Antofagasta</option>
<option value="3" <?php if(isset($_POST['region']) and $_POST['region'] == 3):?> selected <?php endif;?>>III Región de Atacama</option>
<option value="4" <?php if(isset($_POST['region']) and $_POST['region'] == 4):?> selected <?php endif;?>>IV Región de Coquimbo</option>
<option value="5" <?php if(isset($_POST['region']) and $_POST['region'] == 5):?> selected <?php endif;?>>V Región de Valparaíso</option>
<option value="13" <?php if(isset($_POST['region']) and $_POST['region'] == 13):?> selected <?php endif;?>>RM de Santiago</option>
<option value="6" <?php if(isset($_POST['region']) and $_POST['region'] == 6):?> selected <?php endif;?>>VI Región de O´Higgins</option>
<option value="7" <?php if(isset($_POST['region']) and $_POST['region'] == 7):?> selected <?php endif;?>>VII Región del Maule</option>
<option value="8" <?php if(isset($_POST['region']) and $_POST['region'] == 8):?> selected <?php endif;?>>VIII Región del Biobío</option>
<option value="9" <?php if(isset($_POST['region']) and $_POST['region'] == 9):?> selected <?php endif;?>>IX Región de La Araucanía</option>
<option value="14" <?php if(isset($_POST['region']) and $_POST['region'] == 14):?> selected <?php endif;?>>XIV Región de Los Ríos</option>
<option value="10" <?php if(isset($_POST['region']) and $_POST['region'] == 10):?> selected <?php endif;?>>X Región de Los Lagos</option>
<option value="11" <?php if(isset($_POST['region']) and $_POST['region'] == 11):?> selected <?php endif;?>>XI Región de Aysén</option>
<option value="12" <?php if(isset($_POST['region']) and $_POST['region'] == 12):?> selected <?php endif;?>>XII Región de Magallanes</option>
</select>
<input type="submit" value="Buscar">
</form>
<?php
if (isset($_GET['examen1'])) {
$PorRegion = ($_GET['examen1']);
$examen1 = $PorRegion;
$result = mysqli_query($conn, "SELECT * FROM comunas WHERE region = $PorRegion");
}
?>