It seems the output from the postgre database is in tabular format which requires some formatting.
Try to put the following code snippet in your script
I see, It seems that you have to loop through the output that came from postgre database table and and rebuild that table to be in html formatted table.