-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistado.php
55 lines (48 loc) · 1.93 KB
/
listado.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
include 'conexion.php';
$list="";
$database = $_POST['database'];
$tabla = $_POST['tabla'];
//$database = "Autoescuela";
//$tabla = "alumno";
$list.="<pre>";
//Abrimos las etiquetas de <html><head><title><body>y<table>
$list.="<html>
<head>
<title>Listado ".$tabla."</title>
</head>
<body>
<p align=\"center\">Lista de ".$tabla."</p>
<table border = 1 cellspacing=0 cellpadding=2 align=\"center\"><br>";
//Esto recoge el encabezado de la tabla <th></th>
$list.=" <?php<br>";
$list.=" //Recoger el encabezado de la tabla desde la base de datos<br>";
$list.=" \$db = new PDO('mysql:host=localhost;dbname=".$database."', 'root', 'root');<br>";
$list.=" \$sql = \"select * from `information_schema`.`COLUMNS` where `TABLE_SCHEMA`='".$database."' AND table_name = '".$tabla."'\";<br>";
$list.=" \$con = \$db->query(\$sql);;
\$tabla.=\"<tr>\";
foreach(\$con as \$row){
\$tabla.=\"<th>\".\$row['COLUMN_NAME'].\"</th>\";
}
\$tabla.=\"</tr>\";<br>";
//Esto rellena los datos de la tabla
$list.= " \$sql = \"SELECT * FROM ".$database.".".$tabla."\";";
$list.="<br> \$con = \$db->query(\$sql);
foreach(\$con as \$row){<br>";
$list.=" \$tabla.=\"<tr>\";
\$i = 0;
while(\$i < sizeof(\$row)/2){
\$tabla.=\"<td>\".\$row[\$i].\"</td>\";
\$i++;
}<br>";
$list.=" \$tabla.=\"</tr>\";
}
echo \$tabla;
?><br>";
//Cerrar <tabla><body>y<html>
$list.=" </table>
</body>
</html>";
$list.="</pre>";
echo $list;
?>