query( 'select Name, Population, SurfaceArea from country order by Population desc' ); $rows = $result->fetch_all(MYSQLI_ASSOC); echo format_html_table($rows, 'countrytable'); function format_html_table ($rows, $tableid) { $html = ""; $thead = "\n\n\n"; $html .= "\n\n\n"; foreach ($rows as $rownum => $row ) { foreach ($row as $colname => $colvalue) { if ($rownum == 0) { $thead .= sprintf(" \n", $colname); } $html .= sprintf(" \n", $colvalue); } $html .= "\n"; } $html = $thead ."\n". $html; $html .= "\n
%s%s
"; return $html; } ?>