Logre resolverlo. asi fue el resultado independientemente de la consulta arroja los resultados.

Código: text
Gracias.

<?php
session_start();
require('temporal_connection.php');
if (isset($_POST['query']) && !empty($_POST['query'])) {
$consulta = $_POST['query'];
$cantidadColumnas;
$i = 0;
$result = mysql_query($consulta, $conexion)or die("Error de consulta<hr> " . mysql_error());
$dato = mysql_fetch_array($result);
echo "<table class='table table-hover table-bordered'>";
echo "<tr>";
foreach ($dato as $key => $value) {
if (($i % 2) != 0) {
echo "<th>" . $key . "</th>";
$cantidadColumnas++;
}
$i++;
}//end foreach
echo "</tr>";
$files = mysql_query($consulta, $conexion)or die("Error en la consulta<hr>" . mysql_error());
$i = 1;
$x = 0;
while ($registros = mysql_fetch_array($files)) {
if ($i == 1) {
echo "<tr>";
}
foreach ($registros as $key => $value) {
if (($x % 2 ) == 0) {
echo"<td>" . $value . "</td>";
}
$x++;
}
if ($i <= $cantidadColumnas) {
echo "</tr>";
$i = 0;
}
}//end while
echo "</table>";
}
?>
Gracias.