How to open a new window through PHP with the results of a SELECT?

Asked

Viewed 462 times

0

I have a form in which the user will be able to select several subjects, being then selected a subject, through PHP I will pull from the database by SELECT and I will show on the screen with echo the results.

My code :

<form id = "questions_form" method= "post">
   <select class= "box-select" name="select1">
      <option value="value1">Estrutura de Banco de Dados</option>                         
   </select>
   <input type="submit"  name="submit" value="Resultado"/>
   <div class = "resultados-lista">
      <?php
      $query = "SELECT def_conteudo FROM conteudo WHERE nome_conteudo = 'Estrutura de Banco de Dados' ";

      $result = mysqli_query($con,$query);

      if(isset($_POST['select1'])){
         $select1 = $_POST['select1'];
         switch ($select1) {
            case 'value1':
               echo  "<li>" . $fetch[0] . "</li>";
            break;

            default:
            # código
            break;
         }
      }
      ?>
   </div>
</form>
</div>
</div>

But because many of the stories have more than 30 questions, it is very bad and unviable that they are shown on the same page. On account of this, I would like to give a target on a new page to only show these questions. But I don’t know how I can do this.

2 answers

1

You can put one more attribute in the form, the action, when the form is submitted, will be directed to that other page. On this other page that will be consulted to the bank and displayed the result.

Further explanations here, here and in the w3c

1


What you can do is:

<form id = "questions_form" method= "post" action="resultado.php">
   <select class= "box-select" name="select1">
      <option value="value1">Estrutura de Banco de Dados</option>                         
   </select>
   <input type="submit"  name="submit" value="Resultado"/>
</form>

And create a result.php file with the result.

      <?php

      $query = "SELECT def_conteudo FROM conteudo WHERE nome_conteudo = 'Estrutura de Banco de Dados' ";
      $result = mysqli_query($con,$query);

      if(isset($_POST['select1'])){
         $select1 = $_POST['select1'];
         switch ($select1) {
            case 'value1':
               echo  "<li>" . $fetch[0] . "</li>";
            break;

            default:
            # código
            break;
         }
      }
      ?>

That will certainly work.

Browser other questions tagged

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