Displaying records in a dynamically created table

0

I have a MySQL table that has a MySQL query. I have a MySQL table with the following data:

    mysql_select_db($database_conCurriculo, $conCurriculo);
    $query_rsRegistro = "SELECT nome, email, celular, id_municipio, id_uf, dt_nascimento FROM candidato WHERE id_candidato = 158";
    $rsRegistro = mysql_query($query_rsRegistro, $conCurriculo) or die(mysql_error());
    $row_rsRegistro = mysql_fetch_assoc($rsRegistro);
    $totalRows_rsRegistro = mysql_num_rows($rsRegistro);


//Pegando os nomes dos campos
$numCampos = mysql_num_fields($rsRegistro);//Obtém o número de campos do resultado

for($i = 0;$i<$numCampos; $i++){//Pega o nome dos campos
    $Campos[] = mysql_field_name($rsRegistro,$i);
}

//Montando o cabeçalho da tabela
$tabela = '<table border="1"><tr>';

for($i = 0;$i < $numCampos; $i++){
    $tabela .= '<th>'.$Campos[$i].'</th>';
}

//Montando o corpo da tabela
$tabela .= '<tbody>';
while($r = mysql_fetch_array($rsRegistro)){
    $tabela .= '<tr>';
    for($i = 0;$i < $numCampos; $i++){
        $tabela .= '<td>'.$r[$Campos[$i]].'</td>';
    }
    $tabela .= '</tr>';

    echo $tabela;

}
exit;

//Finalizando a tabela
$tabela .= '</tbody></tabela>';

//Imprimindo a tabela
echo $tabela;
    
asked by anonymous 30.06.2014 / 15:23

1 answer

2

I refined my query by assembling and displaying the table differently, as I was unable to resolve the problem of displaying the data from the previous one.

// Consultando candidados no banco
foreach($checkboxes as $id) {

    mysql_select_db($database_con, $con);
    $query_rsRegistro = "SELECT nome, email, celular, id_municipio, id_uf, dt_nascimento FROM candidato WHERE id_candidato = '$id'";
    $rsRegistro = mysql_query($query_rsRegistro, $con) or die(mysql_error());
    $row_rsRegistro = mysql_fetch_assoc($rsRegistro);
    $totalRows_rsRegistro = mysql_num_rows($rsRegistro);

    $Nome = $row_rsRegistro['nome'];
    $Email = $row_rsRegistro['email'];
    $Celular = $row_rsRegistro['celular'];
    $Municipio = $row_rsRegistro['id_municipio'];
    $UF = $row_rsRegistro['id_uf'];
    $Nascimento = $row_rsRegistro['dt_nascimento'];

    $tabela = "     
     <table width=100%  border=0 cellpadding=2 cellspacing=1>
      <tr>
        <td>Nome</td>
        <td>E-mail</td>
        <td>Celular</td>
        <td>Municipio</td>
        <td>UF</td>
        <td>Nascimento</td>
      </tr>";            
    do {            
      $tabela .= "
      <tr>
        <td>{$Nome}; </td>
        <td>{$Email}; </td>
        <td>{$Celular}; </td>
        <td>{$Municipio};</td>
        <td>{$UF};</td>
        <td>{$Nascimento};</td>     
      </tr>";
    } while ($row_rsRegistro = mysql_fetch_assoc($rsRegistro)); 
    $tabela .= "</table>";  

}
    
01.07.2014 / 17:48