Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/12/2019, 00:18
marianomartelli
 
Fecha de Ingreso: agosto-2012
Ubicación: Barcelona
Mensajes: 243
Antigüedad: 11 años, 8 meses
Puntos: 1
Sumar totales de una busqueda que coincida

Buenos días,

Tengo el siguiente problema el que no se solucionarlo y no se si con php o javascript.

Tengo un programa que muestra en pantalla todas las facturas ingresadas, esto lo hace bien, lo que necesito es que cuando se realice una búsqueda, para una empresa en concreto, me de los totales de venta de esa empresa.
He puesto una sumatoria de total, que hace bien si muestra todas las facturas, pero al seleccionar un cliente, la sumatoria va mal.

Aquí el codigo

Código HTML:
Ver original
  1. <?php
  2.     include ('conexion.php');
  3.   $con=conectar();
  4.    
  5.    
  6.     $consulta="SELECT * FROM facturas ORDER by empresa";
  7.     $datos=mysqli_query($con, $consulta);
  8.    
  9.     $total = 0;
  10.     $empresa="";
  11.    
  12. ?>
  13.  
  14.  
  15. <!DOCTYPE html>
  16. <html lang="es">
  17.  
  18.      <head>
  19.      
  20.         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
  21.        
  22.         <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximun-scale=1.0, minimum-scale=1.0">
  23.         <link rel="stylesheet" href="css/bootstrap.min.css">
  24.         <link rel="stylesheet" href="css/bootstrap-theme.css">
  25.         <link rel="stylesheet" href="css/dataTables.bootstrap.min.css">
  26.         <link rel="stylesheet" href="css/bootstrap-glyphicons.css">
  27.         <link rel="stylesheet" href="css/jquery.dataTables.min.css">
  28.        
  29.         <script src="js/jquery.js"></script>
  30.         <script src="js/bootstrap.min.js"></script>
  31.         <script src="js/jquery.dataTables.min.js"></script>
  32.         <script src="js/dataTables.bootstrap.min.js"></script> 
  33.        
  34.         <script>
  35.         $(document).ready(function () {
  36.         $('#mitabla').DataTable({
  37.            "order": [[2, "asc"]],
  38.            "language":{
  39.            "lengthMenu": "Mostrar _MENU_ registros por pagina",
  40.            "info": "Mostrando pagina _PAGE_ de _PAGES_",
  41.            "infoEmpty": "No hay registros disponibles",
  42.            "infoFiltered": "(filtrada de _MAX_ registros)",
  43.            "loadingRecords": "Cargando...",
  44.            "processing": "Procesando...",
  45.            "search": "Buscar:",
  46.            "zeroRecords": "No se encontraron registros coincidentes",
  47.            "paginate": {
  48.                "next":  "Siguiente",
  49.                "previous": "Anterior"
  50.                  },  
  51.               }        
  52.                
  53.            });
  54.        
  55.          });
  56.         </script>
  57.        
  58.          
  59.          
  60.        
  61.      
  62.          <title>Listado Facturas x clientes x pantalla</title>
  63.      </head>
  64.      
  65.      
  66.      <body>
  67.      
  68.      <div class="container">
  69.           <div><br></div>
  70.           <h2 style="text-align: center;">Listado de Facturas x Cliente</h2>
  71.          
  72.           <div class="row">
  73.               <a href="index.php" class="btn btn-info" role="button">Volver</a>
  74.           </div>
  75.    
  76.      
  77.      <br>
  78.      <div class="row table-responsive">
  79.        <table class="display" id="mitabla">
  80.           <thead>
  81.              <tr>
  82.          
  83.                 <th>Id</th>
  84.                     <th>Numero Factura</th>
  85.                     <th>Empresa</th>
  86.                     <th>Fecha factura</th>
  87.                     <th>Importe</th>
  88.                     <th>Total</th>
  89.                     <th>Modificar</th>
  90.                     <th>Eliminar</th>
  91.          
  92.              </tr>
  93.           </thead>
  94.          
  95.           <tbody>
  96.          
  97.          
  98.           <?php while($row = mysqli_fetch_array($datos))
  99.          {
  100.          
  101.            if( $row['empresa'] != '$empresa') {
  102.                
  103.    
  104.                     $total = $total+$row['total'];
  105.                     $valorgral= $total;  
  106.                    $valorgral=number_format($valorgral, 2, ',', '.');  
  107.            
  108.          
  109.          ?>
  110.          
  111.          
  112.          
  113.           <tr>
  114.            
  115.              <td><?php echo $row['id']; ?></td>
  116.              <td align="center"><?php echo $row['numfac']; ?></td>
  117.              <td><?php echo $row['empresa']; ?></td>
  118.              <td ><?php echo $row['fechafac']; ?></td>
  119.              <td><?php echo $row['total']; ?></td>
  120.              <td><?php echo $valorgral; ?></td>
  121.              <td><a href="modifpos1.php?id=<?php echo $row['id'];?>"><img src='iconos/44.png' /></a></td>
  122.              <td><a href="elimpos1.php?id=<?php echo $row['id'];?>"><img align=center  src='iconos/eliminar.png' /></a></td>
  123.          
  124.           </tr>
  125.          <?php  }}?>
  126.          
  127.          
  128.          
  129.           </tbody>
  130.      
  131.       </table>
  132.      
  133.       </div>
  134.      </div>
  135.  
  136.      
  137.      
  138.      </body>
  139.      
  140.  
  141.      
  142.  </html>