Abhijeet Sridhar Abhijeet Sridhar - 4 months ago 22
PHP Question

How to format the php code to display this better

I have this code:

$sql = 'SELECT * from page';
$result = $pdo->query($sql);
$rows = $result->fetchAll(PDO::FETCH_ASSOC);

if(count($result)) {
echo '<table><tr>';
foreach ($rows[0] as $columnName => $value) {
echo '<th>' . $columnName . '</th>';
echo '</tr>';
foreach ($rows as $row) {
echo '<tr>';
foreach ($row as $value) {
echo '<td>' . $value . '</td>';
echo '<tr>';
echo '</table>';

This code is working fine. But since my table is huge, this is apprearing to be very very clumsy - almost unreadable. And I don't know how to make it appear better. I tried adding spaces and adding tabs but no use. I can't understand how to do it. I got this code from my friend. Can anyone modify the code so as to add at least a tab space between every coloumn. Help would me really appreciated.


You can for example do the following: instead of

echo '<table><tr>';


echo '<table border="1"><tr>';

It will put border on your table and it will be easier to differentiate between cells