MysqlPDOPhp

How to display mysql data in table format using pdo?

display mysql data in table format using pdo

Views

Hello to all, welcome to therichpost.com. 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:

<?php
$QUERY = $DBH->prepare(“SELECT * from user”);
$QUERY->execute();
$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)
{
$i++;
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. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, 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.

Positive SSL