Return of values from a column of table X that has 1 code in common

Asked

Viewed 19 times

-1

I need to solve a big problem. I have a table of answers of a poll where the answers made with checkboxes are in different lines with a common code, that of the answered question, example: cod_questao = 100 / cod_answer = 200 cod_questao = 100 / cod_reply = 201. as there are two lines I cannot in foreach() make them come in a single line in html. Do you have an example so I can try to solve this problem?

  • It is not clear what your problem is. You can express yourself better?

  • Thanks for coming to solve my problem with the code, I ended up solving with my superior here from the internship. We had to modify the query in a DAO method that had been created not to repeat on the screen twice the same cod_questao field for example and only repeat the answer. thanks again

  • Put the solution so that other users can see

1 answer

0

If I understand correctly, the bank records are more or less like this:

cod_questao cod_reply

  1            200
  1            300
  2            100
  2            200

Then you will have to do the foreach by controlling the line break, more or less this way:

$questao ='';
foreach($array_de_respostas as $resposta){
    if($questao != $respostas['id_questao']){
       if ($questao != ''){
          //procedimento para fechar a linha anterior, se o $questao for vazio é a primeira vez então não precisa fechar
       }
       $questao = $respostas['id_questao']; 
       //procedimento para abrir a linha
    }
    //procedimento da formação da linha 
}

Browser other questions tagged

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