function query($q) { $qry = mysql_query($q); $keys = array(); $values = array(); $i = 0; while($row = mysql_fetch_array($qry)) { // colunas foreach($row as $key=>$value) { if(!is_numeric($key)) { // processar key if(!in_array($key, $keys)) { $keys[] = $key; } // processar value $values[$i][] = $value; } } $i++; } // criar tabela $out = ''; // criar header foreach($keys as $c) { $out .= ''; } $out .= ''; // processar linhas foreach($values as $l) { $out .= ''; foreach($l as $d) { $out .= ''; } $out .= ''; } $out .= '
'.$c.'
'.$d.'
'; return $out; }