How to make the answer enter immediately after the question?

0

I have a form and I want to send the questions and answers to a database. I took the question in the form of text and sent it to an input hidden field and I want to insert the question and answer in the database:

<label for="pergunta">Como programar em PHP?</label>
<input type="hidden" name="pergunta[]" value="Como programar em PHP?" />
<input type="text" name="resposta[]" value="Estude na documentação do PHP.net" />

You have several questions fed by a foreach. How to iterate the questions with the answers and get something like:

  

How to program in PHP? Study the PHP.net documentation

I thought of something like:

$pergunta = $_POST["pergunta"]; // vai retornar um array
$resposta = $_POST["resposta"]; // vai retornar um array

foreach(){

}
    
asked by anonymous 04.12.2016 / 19:16

1 answer

2

Ideally you should already enter the question in the answers, type the code of the question, in the field for example

<input type="text" name="pergunta[idDaPergunta][resposta]" value="" />

In the controller you will get

$this->input->post("pergunta");

Already brings you all the data of the question and answer (s).

    
07.12.2016 / 22:07