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

0

I have a form in which the user can select several materials, and then a subject is selected, through PHP I will pull the database by SELECT and I will show on the screen with echo 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 subjects have more than 30 questions, it is very bad and unfeasible that they be shown on the same page. Because of this, I'd like to give target on a new page just to show these questions. But I do not know how I can do this.

    
asked by anonymous 30.11.2017 / 23:19

2 answers

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;
         }
      }
      ?>

This will certainly work.

    
30.11.2017 / 23:44
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 that other page, the bank will be consulted and the result displayed.

More explanations here , a href="https://secure.php.net/manual/en_US/tutorial.forms.php"> here and at w3c

    
30.11.2017 / 23:30