Jump to content


Photo

Agrupamento De Dados Com Quantidade De Colunas


  • Faça o login para participar
Nenhuma resposta neste tópico

#1 Luis Vagner

Luis Vagner

    Novato no fórum

  • Usuários
  • 9 posts
  • Sexo:Não informado

Posted 22/08/2011, 15:18

Olá pessoal!
Eu tenho uma função que monta os dados conforme a quantidade de colunas informada.

Estou com um problemão e não estou conseguindo resolver...
Eu coloquei fixo os títulos das colunas (depois vou acertar para fazer dinamico também) e precisava mostrar os dados em suas suas respectivas colunas, já quebrei a cabeça e não estou conseguindo.
Alguém poderia me dar uma força?

Segue abaixo a tabela com os registros e o código.

TABELA E REGISTROS:
CREATE TABLE IF NOT EXISTS `mov_tratamentos` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `IDMOVASSISTIDOS` bigint(20) NOT NULL,
  `IDTRATAMENTOS` bigint(20) NOT NULL,
  `DATA` date NOT NULL,
  `HORA` time NOT NULL,
  `OBSERVACAO` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=42 ;

--
-- Extraindo dados da tabela `mov_tratamentos`
--

INSERT INTO `mov_tratamentos` (`ID`, `IDMOVASSISTIDOS`, `IDTRATAMENTOS`, `DATA`, `HORA`, `OBSERVACAO`) VALUES
(20, 18, 9, '2011-03-22', '00:00:00', 'dsgdfssgdfg'),
(31, 20, 1, '2011-06-06', '12:06:16', ''),
(18, 12, 2, '2011-03-22', '00:00:00', 'erwretrwet'),
(13, 12, 9, '2011-03-22', '00:00:00', 'TESTE 01'),
(29, 20, 9, '2011-06-06', '12:06:07', ''),
(17, 12, 2, '2011-03-22', '14:03:02', 'erwretrwet TESTE'),
(25, 19, 9, '2011-03-22', '13:03:15', 'fhfgdhfghfghghdgdfgf'),
(30, 20, 9, '2011-06-06', '12:06:12', ''),
(32, 20, 5, '2011-06-06', '13:06:13', ''),
(33, 20, 9, '2011-06-06', '14:06:14', ''),
(34, 20, 9, '2011-06-06', '14:06:25', ''),
(35, 20, 2, '2011-06-06', '14:06:33', ''),
(36, 20, 1, '2011-06-03', '14:06:45', ''),
(37, 20, 9, '2011-06-06', '17:06:42', ''),
(38, 20, 9, '2011-06-07', '09:06:02', ''),
(39, 20, 2, '2011-06-07', '09:06:19', ''),
(40, 20, 8, '2011-06-07', '11:06:44', ''),
(41, 20, 1, '2011-06-08', '08:06:25', '');


CÓDIGO PHP
function GeraColunas($pNumColunas, $pQuery) {
$resultado = mysql_query($pQuery);
echo ("<table width='100%' border='1'>\n");

//Titulos das colunas
echo "<td>TRATAMENTO 1</td>\n";
echo "<td>TRATAMENTO 2</td>\n";
echo "<td>TRATAMENTO 5</td>\n";
echo "<td>TRATAMENTO 8</td>\n";
echo "<td>TRATAMENTO 9</td>\n";

for($i = 0; $i <= mysql_num_rows($resultado); ++$i) {

for ($intCont = 0; $intCont < $pNumColunas; $intCont++) {
$linha = mysql_fetch_array($resultado);
if ($i > $linha) {
if ( $intCont < $pNumColunas-1) echo "</tr>\n";
break;
}
 
$codigo	= $linha[0];
$texto 	= $linha[2];
 
if ( $intCont == 0 ) echo "<tr>\n";
echo "<td>". $texto ."</td>\n";
 
if ( $intCont == $pNumColunas-1 ) {
echo "</tr>\n";
} else { $i++; }
}
 
}
echo ('</table>');
}
 
?>        
    
    <table cellSpacing=1 cellPadding=0 width="100%" align=center border=0>
    <tr>
    <td>
    <?
    //*********************************************************************
    // GERA A INSTRUÇÃO SQL E CHAMA A FUNÇÃO PARA GERAR AS COLUNAS
    //*********************************************************************

    $sql = "SELECT * FROM mov_tratamentos WHERE IDMOVASSISTIDOS=20 ORDER BY IDTRATAMENTOS";
    GeraColunas(5, $sql)
    ?>
    </td>
    </tr>
    </table>

Obrigado a todos pela atenção e ajuda!




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq