PHP - imprimir una lista en una tabla.

 
Vista:

imprimir una lista en una tabla.

Publicado por ULISES (1 intervención) el 11/08/2020 02:40:51
Buen día.

Necesito de su ayuda, quiero imprimir una lista en una tabla y quiero hacer que un boton muestre lo que contiene la lista, en mi caso estoy trabajando con varios archivos txt por lo que no les puedo poner un hipervinculo fijo, y quiero que cada archivo tenga su propio boton pero no logro hacerlo.

Este es mi código.

saludos.

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
56
57
58
59
60
61
62
63
64
<?php
	$listar=null;
	$directorio=opendir("archivos/");
	while ($elemento=readdir($directorio))
	{
		if ($elemento!="."&&$elemento!=="..")
		{
			if (is_dir("archivos/".$elemento))
			{
				$listar .="<li><a href='archivos/$elemento' targer='_black'>$elemento/</a></li>";
			}
			else
			{
				$listar .="<li><a href='archivos/$elemento' targer='_black'>$elemento/</a></li>";
			}
		}
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>registros</title>
	<!--<link rel="icon" type="image/png" href="./doctor.png" />-->
  	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<!-- DataTable 1.10.19 14/03/2019-->
	<link rel="stylesheet" type="text/css" href="estilo.css">
	<link rel="stylesheet" type="text/css" href="fonts/style.css">
	<script src="https://kit.fontawesome.com/49fe914f13.js" crossorigin="anonymous"></script>
 
	<!--<link rel="stylesheet" type="text/css" href="../media/alert/dist/sweetalert2.css">-->
</head>
<body>
	<h3>Reportes WEB</h3>
	<div id = "main-cvontainer">
		<table id = "dt_agenda" class = "table table-bordered table-hover" cellspacing = "1" width = "100%">
			<thead>
				<tr>
					<th> Reporte </th>
					<th> Ver </th>
				</tr>
			</thead>
		<?php
			$mostrar=0;
			while ($mostrar>$listar) {
 
		?>
			<tr>
				<td> <?php echo $mostrar; ?> </td>
				<td><center> <button type = 'button' class = 'view btn btn-info'> <i class = 'fas fa-eye'> </i> </button></center> </td>
			</tr>
		<?php
			}
		?>
 
		</table>
	</div>
		</table>
	</div>
</body>
</html>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de javier
Val: 1.542
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

imprimir una lista en una tabla.

Publicado por javier (547 intervenciones) el 11/08/2020 09:00:41
Hola, podrias hacer una cosa como esta, tambien te dejo unos comentarios en el codigo, leelos.

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
$listar=null;
$directorio=opendir("archivos/");
$enlace = [];//creamos un array para guardar la info ordenadamente enlaces
$btn = [];//creamos atro array para guardar botones
while ($elemento=readdir($directorio))
{
if ($elemento != "." && $elemento !== "..")
{
 
 
//ten en cuenta que si es o no un directirio con este IF siempre le asignas un boton y a demas el mismo
//por lo que este if sobraria
if (is_dir($elemento))
{
$enlace [] = "<li><a href='archivos/$elemento' targer='_black'>$elemento/</a></li>";
$btn [] =  "<button type = 'button' class = 'view btn btn-info'> <i class = 'fas fa-eye'> </i> </button>";
}
else
{
$enlace [] = "<li><a href='archivos/$elemento' targer='_black'>$elemento/</a></li><br>";
$btn [] =  "<button type = 'button' class = 'view btn btn-info'> <i class = 'fas fa-eye'> </i> </button>";
}
}
}
 
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>registros</title>
<!--<link rel="icon" type="image/png" href="./doctor.png" />-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- DataTable 1.10.19 14/03/2019-->
<link rel="stylesheet" type="text/css" href="estilo.css">
<link rel="stylesheet" type="text/css" href="fonts/style.css">
 
 
 
<script src="https://kit.fontawesome.com/49fe914f13.js" crossorigin="anonymous"></script>
 
<!--<link rel="stylesheet" type="text/css" href="../media/alert/dist/sweetalert2.css">-->
</head>
<body>
<h3>Reportes WEB</h3>
<div id = "main-cvontainer">
<table id = "dt_agenda" class = "table table-bordered table-hover" cellspacing = "1" width = "100%">
<thead>
<tr>
<th> Reporte </th>
<th> Ver </th>
</tr>
</thead>
<?php
 
$contador = count($enlace);//contamos los elementos que hay en el array
 
//recorremos el array y vamos imprimiendo sus valores
for ($i = 0; $i< $contador; $i++) {
?>
<tr>
<td> <?php echo $enlace [$i]; ?> </td>
<td><center> <?php echo $btn [$i]; ?> </td></td>
</tr>
<?php
}
?>
 
</table>
</div>
</table>
</div>
</body>
</html>
</body>
</html>

Pero si lo que quieres es no asignar enlace ni boton a los directorios yo lo haria de la siguiente manera:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$listar=null;
$directorio=opendir("archivos/");
$enlace = [];//creamos un array para guardar la info ordenadamente enlaces
$btn = [];//creamos atro array para guardar botones
while ($elemento=readdir($directorio))
{
 
 
        //si no es un directorio y por tanto un archivo,  le asigno enlace y boton
 
        if (!is_dir($elemento))
        {
            $enlace [] = "<li><a href='archivos/$elemento' targer='_black'>$elemento/</a></li><br>";
            $btn [] =  "<button type = 'button' class = 'view btn btn-info'> <i class = 'fas fa-eye'> </i> </button>";
        }
 
}
 
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar