Error: Catchable fatal error: Object of class stdClass could not be converted to string in

0

I'm trying to make an html table equal to my database table, however, on the page that is in the table the following error appears:

  

Catchable fatal error: Object of class stdClass could not be converted   to string in

The part of the code responsible for the error is:

<?php
//Conexão e consulta ao Mysql
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'sis_tam');
$qry = mysqli_query($con, "select * from clientes");

//Pegando os nomes dos campos
$num_fields = mysqli_num_fields($qry);//Obtém o número de campos do resultado

for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
    $fields[] = mysqli_fetch_field_direct($qry, $i);
}

//Montando o cabeçalho da tabela
$table = '<table class="table table-hover table-inverse" style="margin-top:50;background-color: #37444a; color:lightgrey;"> <tr>';

for($i = 0;$i < $num_fields; $i++){
    $table .= '<th>'.$fields[$i].'</th>'; //ESSA É A LINHA DO ERRO
}

//Montando o corpo da tabela
$table .= '<tbody style="
    background-color: #86979e;
    color: #37444a;    
">';
while($r = mysqli_fetch_array($qry)){
    $table .= '<tr>';
    for($i = 0;$i < $num_fields; $i++){
        $table .= '<td>'.$r[$fields[$i]].'</td>';
    }

    // Adicionando botão de exclusão
    $table .= '<td><form action="banco/deleteC.php" method="post">'; //formulário com método post que vai para deleteF.php
    $table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
    $table .= '<button  class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
    $table .= '</form></td>';
}

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

//Imprimindo a tabela
echo $table;

?>

The line being pointed to in the error is:

$table .= '<th>'.$fields[$i].'</th>';

I do not use PDO and I do not understand what might be causing the error, could anyone help me?

    
asked by anonymous 24.01.2018 / 12:44

1 answer

0

The problem is that fetch_field_direct returns an object and you can not concatenate that object with a string , for example.

To display the value you must use an attribute: Ex's:

$fields[$i]->name
$fields[$i]->table
$fields[$i]->max_length
$fields[$i]->flags
$fields[$i]->type
    
24.01.2018 / 12:49