0
I don’t know if it’s like that, but what I want to do is basically keep the GET parameters you already have on the page, for example it’s like this:
http://localhost/forum/topic/verTopicos.php? id=1
And I’m sending another GET from a filter that I’m doing, and it’s replacing the current get getting like this
http://localhost/forum/topic/verTopicos.php? filter=answers
The question is, would there be any way to add the filter GET to the top after the ID? Let’s say so:
http://localhost/forum/topic/verTopicos.php? id=1&filter=answers
My code is like this:
if (isset($_GET['id']) && !empty($_GET['id'])) {
$idArea = $_GET['id'];
$sqlArea = mysqli_query($conexao, "SELECT nomeArea FROM area WHERE idArea = '$idArea'");
while ($row = mysqli_fetch_array($sqlArea)) {
$nomeArea = utf8_encode($row['nomeArea']);
}
$ordernar = "posts.dataPost DESC";
// FILTRO
if(isset($_GET['filtro'])){
$filtro = $_GET['filtro'];
switch($filtro){
case ('views'):
$ordernar = "visualizacoes DESC";
break;
case ('autor'):
$ordernar = "Autor DESC";
break;
case ('titulo'):
$ordernar = "topico.titulo ASC";
break;
}
}
<form method="GET" class="form-inline">
<div class="form-group">
<label for="listarPor">Listar por:</label>
<select name="filtro" class="form-control" onchange="this.form.submit()">
<option>Selecione</option>
<option value="views">Visualizações</option>
<option value="autor">Usuário</option>
<option value="respostas">Respostas</option>
<option value="titulo">Título</option>
</select>
</div>
</form>
Thank you Daniel, that was the simplest yet functional solution.
– viniciussvl