-3
I have this code, but the goal was when you click if you see, the table appears, the problem is that every time I click everything disappears, and does not create the table. If I remove the form it gives, but I have to present the 2 tables, and I create that presented according to the user’s choice.
<!--Menu ver-->
      <div id="VFunc">
      <form action = "" method = "post">
        <b>Qual pretenda ver:</b><br>
        <input type="radio" name="gender" value="Dep" required> Departamento
        <input type="radio" name="gender" value="Set" required> Setor
        <input type="submit" name="BtnP" value="Ver">
      </form>
      <?php 
      if (isset($_POST["BtnP"])){
        if ($_POST["gender"]=="Dep"){
          echo "<table>";
          echo"<tr>";
          echo"<th>Id Departamento</th>";
          echo"<th>Nome Departamento</th>";
          echo"</tr>";
          $sql="SELECT * FROM departamentos";
          $result = $conn->query($sql);
        if ($result->num_rows > 0) {
              while($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>$row[IdDepartamento]</td>";
                echo "<td>$row[NomeDepartamento]</td>";
                echo"</tr>";
                echo"</table>";
              }
          }else{
            echo "0 resultados";
          }
        }elseif ($_POST["gender"]=="Set"){ 
          echo "<table>";
          echo"<tr>";
          echo"<th>Id Setor</th>";
          echo"<th>Nome Setor</th>";
          echo"</tr>";
          $sql="SELECT * FROM setores"; 
          $result = $conn->query($sql);
          if ($result->num_rows > 0) {
          while($row = $result->fetch_assoc()) {
            echo "<tr>";
            echo "<td>$row[IdSetor]</td>";
            echo "<td>$row[Nome]</td>";
            echo"</tr>";
            echo"</table>";
          }
            } else {
              echo "0 resultados";
          } 
        }
      }
          $conn->close();
            ?>
      </div>