Ver Mensaje Individual
  #11 (permalink)  
Antiguo 28/01/2014, 13:02
Avatar de NSD
NSD
Colaborador
 
Fecha de Ingreso: mayo-2012
Ubicación: Somewhere
Mensajes: 1.332
Antigüedad: 12 años, 10 meses
Puntos: 320
Respuesta: Como guardar el dato anterior de un while + php ?

Yo haria algo asi mas simple:
Código PHP:
Ver original
  1. <?php
  2.     while($dataGames = $strDataGames->fetch(PDO::FETCH_ASSOC))
  3.     {
  4.             if
  5.             (
  6.                     isset($anterior)
  7.                 &&  ($dataGames['NumGame']  == $anterior['NumGame'])
  8.                 &&  ($dataGames['Teams']    == $anterior['Teams'])
  9.             )
  10.             {
  11.                 // Aca haces lo que quieras.
  12.                
  13.                if(strtotime($anterior['Time']) < strtotime($dataGames['Time']))
  14.                   $anterior['Time'] = $dataGames['Time'];
  15.  
  16.                $anterior['Score']   =  $dataGames['Score'];
  17.                $counterTickets      += $dataGames['Tickets'];
  18.                $counterRisk         += $dataGames['Risk'];
  19.                $counterWinLoss      += $dataGames['WinLoss'];
  20.                $IdGames             .= $dataGames['IdGame']."+";
  21.             }
  22.             else
  23.             {  
  24.                 if(isset($anterior))
  25.                 {
  26.                     // Si no es el primer resultado.
  27.                    
  28.                     $todayFigure += $counterWinLoss; // resto cuando el usuario perdio.
  29.                     $response .= "<tr>
  30.                                 <td>$anterior[Time]</td>
  31.                                 <td>$anterior[NumGame]</td>
  32.                                 <td>$anterior[Teams]</td>
  33.                                 <td>$previousScore</td>
  34.                                 <td><a href=\"#\" onClick=\"openInfoWager(this);\">$counterTickets</a></td>
  35.                                 <td>$counterRisk</td>
  36.                                 <td>$counterWinLoss</td>
  37.                                 <td>$todayFigure</td>
  38.                             </tr>";
  39.                 }
  40.                
  41.                 // Preparar las variables para la proxima ronda.
  42.                 $counterTickets     = 0;
  43.                 $counterRisk        = 0;
  44.                 $counterWinLoss     = 0;
  45.                 $IdGames            = "";
  46.                 $anterior           = $dataGames;
  47.             }
  48.     }
__________________
Maratón de desafíos PHP Junio - Agosto 2015 en FDW | Reglamento - Desafios