Código MySQL:
Ver originalvalues ('Veinte mil leguas de viaje submarino', now(), 0), ('Un capitán de 15 años', now(), 1), ('Los pilares de la tierra', now(), 1), ('Divergente', now(), 0);
Código PHP:
<?php
$mysqlHost = 'localhost';
$mysqlDB = 'dbName';
$mysqlUser = 'userName';
$mysqlPassword = 'userPassword';
$cn = new PDO('mysql:host='.$mysqlHost.';dbname='.$mysqlDB, $mysqlUser, $mysqlPassword);
$qry = 'select id_post, titulo, fecha, leido from post order by id_post desc';
$result = $cn->prepare($qry);
$result->execute();
$xc = '';
$xc .= '<table border="1" cellspacing="3" cellpadding="3" style="border-collapse:collapse;">';
$xc .= '<thead><tr>';
for ($i = 0; $i < $result->columnCount(); $i++)
{
$aux = $result->getColumnMeta($i);
$xc .= '<td>'.$aux['name'].'</td>';
}
$xc .= '</tr></thead>';
$xc .= '<tbody>';
while($row = $result->fetch(PDO::FETCH_NUM))
{
$xc .= '<tr>';
for ($i = 0; $i < $result->columnCount(); $i++) $xc .= '<td>'.trim($row[$i]).'</td>';
$xc .= '</tr>';
}
$xc .= '</tbody>';
$xc .= '</table>';
echo $xc;
?>
Saludos,