tengo el siguiente codigo
//PEDIDOS ENTREGADOS
$resultado_estadistica .= "<h4>ESTADISTICA DE PEDIDOS ENTREGADOS</h4>";
$resultado_estadistica .= '<table id="estadistica" class="table table-bordered table-hover">
<thead>
<tr>
<th>Mes</th>
<th>Ventas Mensual</th>
<th>Mensualidades </th>
</tr>
</thead>
<tbody>';
while ($l = mysqli_fetch_assoc($resultado_epe)){
$dateGroup = $l['dateGroup'];
$monto_total = $l['monto_total'];
$venta_mensual = number_format($monto_total, 2, ',', '.');
$resultado_estadistica .= '<tr>';
$resultado_estadistica .= '<td>'.$dateGroup.'</td>
<td>'.$venta_mensual .' BsS'.'</td>';
while ($j = mysqli_fetch_assoc($result_apa))
{
$resultado_estadistica .= '<td>'. $j['monto_total2'] .' BsS</td></tr>';
}
$resultado_estadistica .= '</td></tr>';
}
$resultado_estadistica .= '</tbody></table>';
Mi idea es hacer que la variable $j['monto_total2']
se enliste en la ultima columna de mi tabla y no se como hacerlo y he intentado ya varias opciones.
Lo que me gustaria lograr:
Mes Ventas Mensual Mensualidades
enero 10 20
febrero 10 10
marzo 10 30
Aplicando la sugerencia tengo como resultado lo siguiente:
//PEDIDOS ENTREGADOS
$resultado_estadistica .= "<h4>ESTADISTICA DE PEDIDOS ENTREGADOS</h4>";
$resultado_estadistica .= '<table id="estadistica" class="table table-bordered table-hover">
<thead>
<tr>
<th>Mes</th>
<th>Ventas Mensual</th>
<th>Mensualidades </th>
</tr>
</thead>
<tbody>';
//setlocale(LC_ALL, 'es_VE.UTF-8');
while ($l = mysqli_fetch_assoc($resultado_epe)){
$dateGroup = strtoupper($l['dateGroup']);
$monto_total = $l['monto_total'];
$venta_mensual = number_format($monto_total, 2, ',', '.');
$resultado_estadistica .= '<tr>';
$resultado_estadistica .= '<td>'.$dateGroup.'</td>
<td>'.$venta_mensual .' BsS'.'</td>';
while ($j = mysqli_fetch_assoc($result_apa))
{
$monto_total2 = $j['monto_total2'];
$m = number_format($monto_total2, 2, ',', '.');
$resultado_estadistica .= '<td colspan="3" align="right">'.$m .' BsS</td></tr>';
}
//$resultado_estadistica .= ' ';
}
$resultado_estadistica .= '</tbody></table>';
Y esta es la salida en el navegador:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<table id="estadistica" class="table table-bordered table-hover">
<thead>
<tr>
<th>Mes</th>
<th>Ventas Mensual</th>
<th>Mensualidades </th>
</tr>
</thead>
<tbody><tr><td>ENERO 2019</td>
<td>10,00 BsS</td><td colspan="3" align="right">10,00 BsS</td></tr><tr><td colspan="3" align="right">10,00 BsS</td></tr><tr><td colspan="3" align="right">100,00 BsS</td></tr><tr><td colspan="3" align="right">10,00 BsS</td></tr><tr><td>DICIEMBRE 2018</td>
<td>10,00 BsS</td></tr><tr><td>NOVIEMBRE 2018</td>
<td>10,00 BsS</td></tr><tr><td>OCTUBRE 2018</td>
<td>10,00 BsS</td></tr></tbody></table>
Estructura de mis 2 tablas
# Nombre Tipo Cotejamiento Atributos Nulo Predeterminado
#ESTRUCTURA DE LA TABLA PAGOS
1 idPrimaria int(11) No Ninguna AUTO_INCREMEN
2 user varchar(12) latin1_spanish_ci No Ninguna
3 monto varchar(100) latin1_spanish_ci No Ninguna
4 concepto varchar(200) latin1_spanish_ci No Ninguna
5 mes_de_pago varchar(30) latin1_spanish_ci No Ninguna
6 afiliacion varchar(30) latin1_spanish_ci No Ninguna
7 banco_origen varchar(200) latin1_spanish_ci No Ninguna
8 banco_destino varchar(200) latin1_spanish_ci No Ninguna
9 nro_transfÍndice varchar(100) latin1_spanish_ci No Ninguna
10 ci_nro_cuenta varchar(20) latin1_spanish_ci No Ninguna
11 fecha_transf timestamp on update CURRENT_TIMESTAMP No CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM
12 fecha_pago timestamp No CURRENT_TIMESTAMP
13 status_pago varchar(30) latin1_spanish_ci No Ninguna
14 motivo_rechazo text latin1_spanish_ci
#ESTRUCTURA DE LA TABLA PEDIDO
1 idPrimaria int(11) No Ninguna AUTO_INCREMENT
2 usuario varchar(200) latin1_spanish_ci No Ninguna
3 monto varchar(10) latin1_spanish_ci No Ninguna
4 nro_transfÍndice varchar(100) latin1_spanish_ci No Ninguna
5 banco_emisor varchar(100) latin1_spanish_ci No Ninguna
6 banco_destino varchar(100) latin1_spanish_ci No Ninguna
7 fecha_transf timestamp Sí NULL
8 ci_nro_cuenta varchar(20) latin1_spanish_ci No Ninguna
9 status_pedido varchar(50) latin1_spanish_ci No Ninguna
10 fecha_pedido timestamp Sí CURRENT_TIMESTAMP
11 fecha_aprobacion timestamp Sí NULL
12 motivo_rechazo text latin1_spanish_ci Sí NULL
13 fecha_rechazo timestamp Sí NULL
while
tampoco se ve claro de dónde sale la 2ª columna o qué ocurre en ese 2ºwhile
. Para mostrar un total, la lógica a seguir sería construir todas las filas con sus tres columnas y sus datos dentro del bucle y fuera del bucle agregar otra fila parecida a esto:'<tr><td colspan="3">TOTAL: '.$valorTotal.'</td></tr>
ID
... si de hecho quieres mostrar esa info junta es porque tienen relación de alguna manera (me refiero a la lógica real que debería seguir tu programa), otra cosa es que los datos no se hayan diseñado relacionados, lo cual podría hacerse. Pero ese es otro asunto. Para mostrar el total al final, tienes que poner algo como esto cuando termines de llenar todas la filas:'<tr><td colspan="3" align="right">TOTAL: '.$valorTotal.'</td></tr>';
elcolspan
es para que, en esa fila última junte las tres celdas que tiene tu tabla en una sola.$j['monto_total2']
hay varios valores que quieres sumar dentro del 2ºwhile
, entonces puedes declarar una variable, e irla acumulando dentro. Declaras$valorTotal=0;
fuera de todos loswhile
y dentro del 2º pones algo así:while ($j = mysqli_fetch_assoc($result_apa)) { $valorTotal= valorTotal + $j['monto_total2']; }
y luego muestras el valor acumulado en la última fila como ya se indicó en el anterior comentario.