traer un array de una consulta en una funcion para llenar tabla
Publicado por julio (9 intervenciones) el 13/11/2019 12:48:41
Hola a todos, tengo el siguiente inconveniente tengo una función en php que tiene dos consultas a la base de datos, obtengo dos array y los agrego a un tercer array para retornarlos a 2 tablas que están en otro archivo php adjunto función que esta en el archivo funciones.php y los envío a principal.php que posee el esqueleto de las tablas algo no funciona con la carga de datos en la tabla me trae datos repetidos en la tabla 1, me parece que el while no recorre bien la información que paso? Creo. Desde ya muchas gracias
funciones.php
Adjunto las tablas del archivo principal.php
la otra tabla
utilizo while ($arreglo1= tabprincipal()[1]) para cargar la tabla "tabprincipal es la funcion declarada en funciones.php que llamo en el archivo principal.php, Desde ya muchas gracias
funciones.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function tabprincipal() {
include "conexion.php";
$id_area = $_SESSION['id_area'];
$sql4 = mysqli_query($conn, "SELECT productos.name, cantidad_sal, date_sal from salidas, productos where salidas.id_area = '$id_area' and productos.id_producto = salidas.id_producto order by date_sal desc LIMIT 5");
$prodsal = mysqli_fetch_array($sql4);
$sql5 = mysqli_query($conn, "SELECT productos.name, productos.stock_actual, productos.fecha_ingreso from productos, entradas where productos.id_area = '$id_area' order by date_ent desc LIMIT 5");
$prodent = mysqli_fetch_array($sql5);
return array($prodsal, $prodent);
mysqli_close($conn);
}
Adjunto las tablas del archivo principal.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
<table class="table table-bordered table-condensed" id="sampleTable1" >
<thead>
<tr>
<th class='text-center'>Producto</th>
<th class='text-center'>Cantidad entregada</th>
<th class='text-center'>Fecha</th>
</tr>
</thead>
<tbody>
<?php
while ($arreglo1 = tabprincipal()[0]) {
echo "<tr>";
echo "<td style='min-width:40px;'>$arreglo1[0]</td>";
echo "<td class='text-center' style='max-width:140px;'>$arreglo1[1]</td>";
echo "<td class='text-center' style='max-width:140px;'>$arreglo1[2]</td>";
}
?>
<?php echo "</tr>"; ?>
</tbody>
</table>
la otra tabla
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
<table class="table table-bordered table-condensed" id="sampleTable1" >
<thead>
<tr>
<th class='text-center'>Producto</th>
<th class='text-center'>Cantidad añadida</th>
<th class='text-center'>Fecha</th>
</tr>
</thead>
<tbody>
<?php
while ($arreglo1 = tabprincipal()[1]) {
echo "<tr>";
echo "<td style='min-width:40px;'>$arreglo1[0]</td>";
echo "<td class='text-center' style='max-width:140px;'>$arreglo1[1]</td>";
echo "<td class='text-center' style='max-width:140px;'>$arreglo1[2]</td>";
}
?>
<?php echo "</tr>"; ?>
</tbody>
</table>
utilizo while ($arreglo1= tabprincipal()[1]) para cargar la tabla "tabprincipal es la funcion declarada en funciones.php que llamo en el archivo principal.php, Desde ya muchas gracias
Valora esta pregunta


0