Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/04/2017, 12:01
Avatar de aviweb2015
aviweb2015
 
Fecha de Ingreso: abril-2016
Ubicación: venezuela
Mensajes: 215
Antigüedad: 8 años, 10 meses
Puntos: 1
Busqueda mostrar la suma total por cada piloto y mostrarla en variable

saludos amigos estoy tratando de hacer esto http://www.caranddriver.es/formula-1/clasificacion/2017, una tabla de clasificación de pilotos pero el único problema que tengo que no me muestra la suma total de puntos bien por cada piloto, osea no me calcula la suma bien. lo demás esta bien el único problema que tengo es eso

anexo mi consulta:

Código PHP:
Ver original
  1. <?php
  2. $sql = "SELECT
  3. clasificacion_pilotos.id,
  4. clasificacion_pilotos.fk_pilotos,
  5. clasificacion_pilotos.au,
  6. clasificacion_pilotos.ch,
  7. clasificacion_pilotos.ba,
  8. clasificacion_pilotos.ru,
  9. clasificacion_pilotos.es,
  10. clasificacion_pilotos.mo,
  11. clasificacion_pilotos.ca,
  12. clasificacion_pilotos.az,
  13. clasificacion_pilotos.at,
  14. clasificacion_pilotos.gb,
  15. clasificacion_pilotos.hu,
  16. clasificacion_pilotos.be,
  17. clasificacion_pilotos.it,
  18. clasificacion_pilotos.sg,
  19. clasificacion_pilotos.ma,
  20. clasificacion_pilotos.ja,
  21. clasificacion_pilotos.usa,
  22. clasificacion_pilotos.me,
  23. clasificacion_pilotos.br,
  24. clasificacion_pilotos.ab,
  25. pilotos.nombresyapellidos FROM clasificacion_pilotos INNER JOIN pilotos ON clasificacion_pilotos.fk_pilotos=pilotos.id
  26. ORDER BY id";
  27. $consulta = $DB_con->prepare($sql);
  28. $consulta->execute();
  29. if($consulta->rowCount() > 0){
  30. $i=1;
  31. echo "<table class='striped responsive-table'>
  32.        <thead>
  33.          <tr>
  34.              <th>Pos.</th>
  35.              <th>Piloto</th>
  36.              <th>Tot.</th>
  37.              <th>AU</th>
  38.              <th>CH</th>
  39.              <th>BA</th>
  40.              <th>RU</th>
  41.              <th>ES</th>
  42.              <th>MO</th>
  43.              <th>CA</th>
  44.              <th>AZ</th>
  45.              <th>AT</th>
  46.              <th>GB</th>
  47.              <th>HU</th>
  48.              <th>BE</th>
  49.              <th>IT</th>
  50.              <th>SG</th>
  51.              <th>MA</th>
  52.              <th>JA</th>
  53.              <th>USA</th>
  54.              <th>ME</th>
  55.              <th>BR</th>
  56.              <th>AB</th>
  57.          </tr>
  58.        </thead>";
  59. while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {
  60.  
  61.  
  62.     $total = array_reduce(array_keys($linea), function($v, $k) use($linea) {
  63.          
  64.           if ($k !== 'linea') {
  65.  
  66.              return $v += $linea[$k];
  67.  
  68.    
  69.          }
  70.      });
  71. ?>
  72.  
  73.           <tr>
  74.             <td><?php echo $i ?></td>
  75.             <td><?php echo $linea['nombresyapellidos']; ?></td>
  76.             <td><b><?php echo $total;?></b></td>
  77.             <td><?php echo $linea['au']; ?></td>
  78.             <td><?php echo $linea['ch']; ?></td>
  79.             <td><?php echo $linea['ba']; ?></td>
  80.             <td><?php echo $linea['ru']; ?></td>
  81.             <td><?php echo $linea['es']; ?></td>
  82.             <td><?php echo $linea['mo']; ?></td>
  83.             <td><?php echo $linea['ca']; ?></td>
  84.             <td><?php echo $linea['az']; ?></td>
  85.             <td><?php echo $linea['at']; ?></td>
  86.             <td><?php echo $linea['gb']; ?></td>
  87.             <td><?php echo $linea['hu']; ?></td>
  88.             <td><?php echo $linea['be']; ?></td>
  89.             <td><?php echo $linea['it']; ?></td>
  90.             <td><?php echo $linea['sg']; ?></td>
  91.             <td><?php echo $linea['ma']; ?></td>
  92.             <td><?php echo $linea['ja']; ?></td>
  93.             <td><?php echo $linea['usa']; ?></td>
  94.             <td><?php echo $linea['me']; ?></td>
  95.             <td><?php echo $linea['br']; ?></td>
  96.             <td><?php echo $linea['ab']; ?></td>
  97.           </tr>
  98.  <?php
  99.        
  100.        $i++;
  101.         }
  102.  
  103.       }
  104.  
  105. else
  106.  
  107. echo "<div class='col s12 card-panel yellow darken-2 center'>
  108. <h5 class='black-text text-darken-2 center CONDENSED LIGHT5'>¡ Advertencia: No se ha encontrado ningún registro !</h5>
  109. </div>";
  110. ?>
  111.  
  112.  
  113.       </table>
__________________
yoclens avilan

Última edición por aviweb2015; 15/04/2017 a las 12:02 Razón: falto algo