Generador de Tablas
Posted on July 16th, 2005 in Código, Php |
Código de ejemplo que genera una tabla de acuerdo al input del usuario. Permite agregar filas y columas.
PHP:
-
<?php
-
/*
-
* Código de Ejemplo
-
* César Sánchez Oropeza jesama@prodigy.net.mx
-
* www.novacreations.net
-
*
-
* Este código es una página que genera una matriz de forma dinámica desplegandola como una tabla,
-
* Permite agregar filas y columnas, y modificar los datos de la misma.
-
*
-
*/
-
-
echo "<html>";
-
echo "<body>";
-
-
// PRIMER ACCESO A LA PAGINA
-
if(!$_POST)
-
{
-
echo "<p>ingresa la cantidad de filas y columnas que deseas para tu tabla</p>";
-
echo"FILAS: <input name=\"filas\" type=\"text\">";
-
echo"COLUMNAS: <input name=\"columnas\" type=\"text\">";
-
echo "<input name=\"boton\" type=\"SUBMIT\" value=\"CREAR\">";
-
echo "</form>";
-
-
-
}
-
{
-
echo "<pre>";
-
echo "</pre>";
-
}
-
else
-
{
-
-
-
-
// creamos la fila o culumna en el arreglo
-
if($_POST['boton']=="Agregar Fila") $_POST['filas']++;
-
if($_POST['boton']=="Agregar Columna") $_POST['columnas']++;
-
-
// almacenamos el valor de las filas y columnas
-
-
//imprimimos los datos de la tabla
-
echo "<table border=\"1\">";
-
echo "<tr><td></td>";
-
for($i = 0; $i < $_POST['columnas'] ; $i++) echo "<td>".$i."</td>"; // imprimimos el numero de las columnas
-
echo "</tr>";
-
for($i = 0; $i < $_POST['filas'] ; $i++) //filas
-
{
-
echo "<tr>";
-
for($j = 0; $j <$_POST['columnas'] ; $j++) //columnas
-
{
-
$art = ""; //inicalizamos la variable
-
}
-
-
echo "</tr>";
-
}
-
-
-
echo "</table>";
-
echo "<input name=\"boton\" type=\"SUBMIT\" value=\"Agregar Fila\">";
-
echo "<input name=\"boton\" type=\"SUBMIT\" value=\"Agregar Columna\">";
-
echo "<input name=\"boton\" type=\"SUBMIT\" value=\"Enviar\">";
-
echo "</form>";
-
}
-
-
-
echo "</body>";
-
echo "</html>";
-
-
-
-
?>
Popularidad: 3%

