Tuesday, November 29, 2022

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.

the authortherichpost
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 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Angular 14, Angular 15, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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