I am trying to perform a sort order of records on a page by firing a List / Menu, but when I fire it, I am losing variable values from a first selection.
When I enter the products page, I already place a $ dep variable and show the result. When trying to make the filter by ASC or DESC the page is reloaded, thus losing the previous search and does not perform the ordering.
I made a few attempts, saved the variables in sessions, and tested the value of the filter variable:
$dep = $_REQUEST['dep']; $subdep = $_REQUEST['sub']; $_SESSION['dep'] = $dep; $_SESSION['sub'] = $subdep; $filtro = $_POST['filtro']; switch ($filtro) { case 1: $ORDER = " ORDER BY produtos.descricao ASC"; break; case 2: $ORDER = " ORDER BY produtos.descricao DESC"; break; default: $order = " ORDER BY produtos.descricao ASC"; }
When selecting a filter option, I'm triggering the filter's value for the products.php page and it looks like this:
And my List / Menu looks like this:
<select name="filtro" id="filtro" onchange="valueselect(this.value);">
function valueselect(filtro) { window.location.href = "produtos.php?filtro="+filtro; }