How do you add a get without replacing what you already have?

Asked

Viewed 36 times

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>

1 answer

1

Shortly after the form, add an Hidden field

<form method="GET" class="form-inline">
<input type="hidden" name="id" value="<?php echo $idArea;?>">

The rest continues as it is.

  • Thank you Daniel, that was the simplest yet functional solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.