Help with PDO data in PHP!

Asked

Viewed 55 times

1

Guys, I’m pulling data from a bank SQLSERVER with PDO for an HTML/PHP page, I used the following code:

$query = "SELECT * FROM [BD].[Feriados]";   
$stmt = $conn->query( $query );   
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){   
   print_r( $row );
  
}  
?>

It returns me the values as follows:

> Array ( [Codigo] => 1 [Data] => 2000-01-01 00:00:00.000 [Descricao] =>
> ano novo [Fixo] => 2 ) Array ( [Codigo] => 2 [Data] => 2000-01-02
> 00:00:00.000 [Descricao] => 2 [Fixo] => 2 ) Array ( [Codigo] => 4
> [Data] => 2018-09-07 00:00:00.000 [Descricao] => INDEPENDENCIA [Fixo]
> => 1 ) Array ( [Codigo] => 11 [Data] => 2018-10-12 00:00:00.000 [Descricao] => DIA N. SRA. APARECIDA [Fixo] => 1 )

I would like to organize this data in a table in HTML, but I’m still a beginner in PHP and would like a help if someone can give me a light to treat this data.

Thank you!

  • Marco Lustosa, welcome, start here for a quick overview of https://answall.com/tour

  • What does it mean when an answer is "accepted"? https://answall.com/help/accepted-answer

  • Mark a response as it accepts https://i.stack.Imgur.com/evLUR.png

1 answer

0


One inserir a descrição da imagem aqui to process the data

$dados = '<table .....>
          <thead>
            <tr><th class="">Código</th><th class="">Data</th>
                <th>Descrição</th><th>Fixo</th>
            </tr>';

while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){   
  $dados .= '<tr><td>'.$row['Codigo'].'</td><td>'.$row['Data'].'</td>
                 <td>'.$row['Descricao'].'</td><td>'.$row['Fixo'].'</td>    
             </tr>';

}

 echo '</thead><tbody>'.$dados.'</tbody></table>';
  • Thank you! Solved my problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.