You are on page 1of 2

<!

DOCTYPE html>
<html>
<head>
<title>Consulta BD con tabla (</title>
</head>
<body>
<h1>Mostrar alumnos registrados</h1>
<?php
$dp = mysql_connect("localhost", "root", "");
mysql_select_db("escuela004", $dp);
$sql = "SELECT * FROM alumnos";
$resultado = mysql_query($sql);
$campos = mysql_num_fields($resultado);
$filas = mysql_num_rows($resultado);
echo "<p>Cantidad de filas: $filas</p>\n";

echo "<table border='2' cellspacing='0'>\n"; //crear tabla
echo "<tr>"; //Crea fila
for ($i = 0; $i < $campos; $i++) {
$nombrecamp = mysql_field_name($resultado, $i);
echo "<th>$nombrecamp</th>";
}
echo "</tr>\n"; //Cerrar fila

while ($row = mysql_fetch_assoc($resultado)) {
echo "<tr>"; //Crear fila
foreach ($row as $key => $value) {
echo "<td>$value&nbsp;</td>";
}
echo "</tr>\n"; //Cerrar fila
}
echo "</table>\n"; //Cerrar tabla

$roww = 150;
echo "<p>Cantidad de filas: $filas</p>\n";


echo "\n Promedio General............................................",$roww/$filas;
mysql_close($dp);

echo "\n";

?>

</body>

You might also like