How to display mysql data in table format using pdo?

display mysql data in table format using pdo

Hello to all, welcome to In this post, I am showing mysql data in table format using pdo. Table format will be same like mysql. This code is very interesting and will show all the data with column names and data structure as same as mysql table structure.

Here is the working code for display mysql data in table format using pdo:

$QUERY = $DBH->prepare(“SELECT * from user”);
$user = $QUERY->fetchAll(PDO::FETCH_ASSOC);
echo “<table class=’table table-hover’><tr>”;
foreach ($user as $value){
$tablename =array_keys($value);
$i = 0;
foreach ($tablename as $key)
echo “<th>”.$key.”</th>”;
echo “</tr>”;
foreach ($user as $key => $value) {
echo “<tr>”;
for ($j=0; $j < $i ; $j++) {
$key = $tablename[$j];

echo “<td>”.$value[$key].”</td>”;
echo “</tr>”;
echo “</table>”;

There are so many queries in pdo for mysql data and I will let you know all. Please do comment if you any query related to this post. Thank you.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.