Categories

Saturday, October 5, 2024
#919814419350 therichposts@gmail.com
MysqlPDOPhp

How to display mysql data in table format using pdo?

display mysql data in table format using pdo

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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, 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.