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
Recent Comments