php mysql查询在一次运行中将字段名称及其数据提取到一个表中

I have tried to prepare a data table where any list query is passed its results would be sown in a table.

I have used 2 if conditions and foreach loop. Now i have doubt that this is would slow down if bulk records are fetched.. Can anyone suggest me much better way to do this..

Query as follows

 echo "<table width='100%' align='center' border=1 style='text-align:center; vertical-align:center; border-collapse:collapse; font-size:80%' class='main'>";
    $i=0;
    while($row=mysqli_fetch_array($result)){
      echo "<tr>";
        foreach($row as $rowvalues => $cellvalues){
            if (!is_numeric($rowvalues)){
               if($i==0){ 
                    echo "<th>".$rowvalues."</th>"; // For Table header
               }else{
                    echo "<td>".$cellvalues."</td>"; // For field values
               }
            }
        }
      echo "</tr>"; 
      $i++;
    }
    echo "</table>";

Create a php pagination to avoid slowing down of fetching records in your database.

maybe this is a bit faster? (reduce the amount of echos)

$output = "<table width='100%' align='center' border=1 style='text-align:center; vertical-align:center; border-collapse:collapse; font-size:80%' class='main'>";
    $i=0;
    while($row=mysqli_fetch_array($result)){
      $output .= "<tr>";
        foreach($row as $rowvalues => $cellvalues){

            if (!is_numeric($rowvalues)){       
                $output .= ($i == 0) ? "<th>".$rowvalues."</th>" : "<td>".$cellvalues."</td>";              
            }
        }
      $output .= "</tr>"; 
      $i++;
    }
    echo $output."</table>";