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

-1

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

    
asked by anonymous 01.02.2017 / 18:15

1 answer

0

If I understand correctly, the registry in the database looks something like this:

cod_questao cod_resposta

  1            200
  1            300
  2            100
  2            200

So you have to do foreach by controlling the line break, more or less like this:

$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 
}
    
01.02.2017 / 21:24