0
I set up a dynamic table with data from a query to Mysql, when I show all the records the table is displayed correctly, but when I request only one record the table does not display any record, see how it is:
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;
Are you sure there’s a record coming in, meaning there’s this 158 candidate?
– Maniero
Hello @bigown, yes this candidate exists, because I do a search in Mysql and it is there.
– adventistapr
Ever tried with another value? Do a test like this:
$query_rsRegistro = "SELECT \
name`, `email`, `celular`, `id_municipio`, `id_uf`, `dt_nascimento` FROM `candidato` WHERE id_candidato = '158'";`– touchmx
Hello @user3043340, yes it was one of the first tests I did, also not that.
– adventistapr
Friend, your code appears to be correct, but I think it is not displaying any record because it has no record, I think your Query returns zero, do a test, try to check if the variable: $totalRows_rsRegister has some value before listing in the table, something else, try to run your Query inside the Database to see which return.
– Lincoln Luiz