regina 0 Denunciar post Postado Outubro 22, 2010 Boa tarde, estou desenvolvendo uma página tipo enquete onde preciso mostrar as colunas e as linhas de uma determinada pergunta, com o seguinte código montando campos de preenchimento (form) dentro de uma tabela. $sql_r=mysql_query("SELECT resposta_id,resposta,outra FROM tb_pesquisa_opiniao_respostas WHERE pergunta_id='".$row["pergunta_id"]."' AND exibir='sim' ORDER BY $order") or die (mysql_error()); <table> <tbody> <tr> <th class="descricao_coluna1"> </th> <?php #colunas $sql_c=mysql_query("SELECT coluna_id, coluna FROM tb_pesquisa_opiniao_colunas WHERE pergunta_id='".$row["pergunta_id"]."' AND exibir='sim' ORDER BY coluna_id ASC") or die (mysql_error()); $reg_col=mysql_num_rows($sql_c); while($col=mysql_fetch_array($sql_c)){?> <th class="descricao_colunas"><?php print $col["coluna"];?></th> <?php } ?> </tr> <?php /*#opções*/$lin=0; while($resp=mysql_fetch_array($sql_r)){ $lin++; if ($lin%2==0) $classe="par"; else $classe="impar";?> <tr class="<?php print $classe; ?>"> <td class="resposta"><?php print $resp["resposta"];?></td> <?php /*inputs*/ for($c=0; $c<$reg_col; $c++) {?> <td><label class="<?php print $classe;?>" for="resposta_<?php print $col["coluna_id"];?>"><?php print $campo;?> name="resposta_<?php print $resp["resposta_id"];?>[]" id="resposta_<?php print $col["coluna_id"];?>" tabindex="<?php print $tab;?>" title="<?php print $resp["resposta"];?>" <?php print $campo_f;?></label></td> <?php } #while($resp=?> </tr> <?php } #while($resp=?> </tbody> </table>onde eu tenho for="resposta_<?php print $col["coluna_id"];?>" ele está sem valor de $col["coluna_id"], minha pergunta:Como devo chamar este valor que em cada linha será diferente? Desde já agradeço Compartilhar este post Link para o post Compartilhar em outros sites
Rodrigo Z 0 Denunciar post Postado Outubro 22, 2010 Olá amigo, Execute um comando após o seu while: echo '<pre>'; print_r($col); echo '</pre>'; exit; Poste o output aqui para darmos uma olhada. Abraço! Compartilhar este post Link para o post Compartilhar em outros sites
regina 0 Denunciar post Postado Outubro 22, 2010 Oi Rodrigo, retornou Citar Array ( [0] => 1 [coluna_id] => 1 [1] => Muito satisfeito [coluna] => Muito satisfeito ) coloquei após o while($col=mysql_fetch_array($sql_c)){ Compartilhar este post Link para o post Compartilhar em outros sites
Rodrigo Z 0 Denunciar post Postado Outubro 22, 2010 No seu array novo, o $resp, ele está definido como? Pelo que parece você faz um while e dentro um outro while! Se possível, utilize de foreach. Mas faça o seguinte, após o primeir while, ponha, $id_coluna = $col['coluna_id']; Faz tempo que não utilizo while, por isso não lembro mais o comportamento dele. Compartilhar este post Link para o post Compartilhar em outros sites
regina 0 Denunciar post Postado Outubro 25, 2010 Bom dia Rodrigo, O $resp está definido anteriormente em outro while: $resp=mysql_fetch_array($sql_r); Ele repete o mesmo id em todos os registros da pergunta. Já havia tentado isso... Como seria usando o foreach, uso-o somente para pegar os valores assim: foreach($_POST as $campo => $valor){ ... } <table> <tbody> <tr> <th class="descricao_coluna1"> </th> <?php #colunas $sql_c=mysql_query("SELECT coluna_id, coluna FROM tb_pesquisa_opiniao_colunas WHERE pergunta_id='".$row["pergunta_id"]."' AND exibir='sim' ORDER BY coluna_id ASC") or die (mysql_error()); $reg_col=mysql_num_rows($sql_c); while($col=mysql_fetch_array($sql_c)){ $coluna_id = $col['coluna_id'];?> <th class="descricao_colunas"><?php print $col["coluna"];?></th> <?php } ?> </tr> <?php /*#opções*/$lin=0; while($resp=mysql_fetch_array($sql_r)){ $lin++; if ($lin%2==0) $classe="par"; else $classe="impar";?> <tr class="<?php print $classe;?>"> <td class="resposta"><?php print $resp["resposta"];?></td> <?php /*inputs*/ for($c=0; $c<$reg_col; $c++) {?> <td><?php echo "col ".$coluna_id;?> <label class="<?php print $classe;?>" for="resposta_<?php print $col["coluna_id"];?>"><?php print $campo;?> name="resposta_<?php print $resp["resposta_id"];?>[]" id="resposta_<?php print $col["coluna_id"];?>" tabindex="<?php print $tab;?>" title="<?php print $resp["resposta"];?>" <?php print $campo_f;?></label></td> <?php } #while($resp=?> </tr> <?php } #while($resp=?> </tbody> </table> Grata Compartilhar este post Link para o post Compartilhar em outros sites