Create Page Loop 3 times [closed]

0

The user will enter the system, make another registration on a page unrelated to that question and will arrive at this directory_director.php page. In the page in question, it will register 3 different directors, being that by having only 1 form, it should go and return 3 times on the same page, how to do that?

    
asked by anonymous 16.02.2017 / 12:31

3 answers

2

With a repeat structure you will not be able to do this, the right thing would be:

directory_director.php

<?php
if(!isset($_SESSION['cadastro_cont'])
    $_SESSION['cadastro_cont'] = 1;

// restante da ação da página

insert_diretor.php

// ação da página
<?php
//no fim, quando terminar de cadastrar:

if($_SESSION['cadastro_cont'] >= 3)
    header('Location: pagina_seguinte.php');

$_SESSION['cadastro_cont'] += 1;
header('Location: cadastro_diretor.php');

The first time you access the registration page, a session variable is created to tell you what the current registration is. In the insert page, after the insert action, I check if the current register represented by this variable is 3 if it is I go to the next screen, if not I assign one more to the counter and call the registration page again.

    
16.02.2017 / 13:26
1

Considering that you have the relationship between the company and director tables in order to store the id of the company in the director's directory, something like: p>

create table empresas 
(
  id int,
  name varchar(255)
);

create table diretores (
  id int,
  name varchar(255),
  empresa int
);

In a file, possibly called insert_empresa.php , the company register is made. For example:

insert into empresas (id, name) values (1, "empresa_1");

This insert generates a id , related to the company record, which is passed to the cadastro_diretor.php file, where the form is displayed. In the insere_diretor.php file, you create the director record by storing the id of the related company in the company field.

insert into diretores (id, name, empresa) values (1, "diretor_1", 1);

To know if the three directors have not yet been registered, just count the number of records in the bank:

select count(*) from diretores where empresa = 1;

Where empresa = 1 refers to id of the company in question. This query returns an integer value and if it is less than 3, redirect the user back to the form page.

See the Ideone and Github Gist .

    
16.02.2017 / 13:34
1

It would be better to put a button in the form of the page cadastro_diretor.php, for the user to add new registrations. There you put a control to allow the user to register up to 3 people or exactly 3 people.

    
16.02.2017 / 14:04