Ver Mensaje Individual
  #24 (permalink)  
Antiguo 29/01/2014, 15:42
Avatar de adryan310
adryan310
 
Fecha de Ingreso: septiembre-2012
Mensajes: 450
Antigüedad: 12 años, 6 meses
Puntos: 3
Exclamación Respuesta: Como guardar el dato anterior de un while + php ?

Amigo le he estado hechando un poco cabeza y ha mejorado un poco, pero aun no me funka mira lo que tengo:
Código PHP:
$conta           0;
                        
$counterTickets  0;
                        
$counterRisk     0;
                        
$counterWinLoss  0;
                        
$IdGames         "";
                        while(
$dataGames $strDataGames->fetch(PDO::FETCH_ASSOC)){
                            if (isset(
$anterior) ){
                                
// Si hay un aterior trabajamos con el. Esto se hace ciempre.
                                
if($conta == 0){
                                   
$counterTickets      += $anterior['Tickets'];
                                   
$counterRisk         += $anterior['Risk'];
                                   
$counterWinLoss      += $anterior['WinLoss'];
                                   
$IdGames             .= $anterior['IdGame']."+";
                                   
                                   
$conta ++;  
                                   
error_log("TICKETS EN PRIMER IF: Juego# ".$anterior['NumGame']." - ".$counterTickets);
                                }
                                
// Verificamos la similitud con el anterior. Si coinciden hago lo que quiero.
                                
if(($dataGames['NumGame']  == $anterior['NumGame']) && ($dataGames['Teams'] == $anterior['Teams'])){
                                       
$counterTickets      += $anterior['Tickets'];
                                       
$counterRisk         += $anterior['Risk'];
                                       
$counterWinLoss      += $anterior['WinLoss'];
                                       
$IdGames             .= $anterior['IdGame']."+";   
                               
                                   if(
strtotime($anterior['Time']) < strtotime($dataGames['Time']))
                                      
$anterior['Time'] = $dataGames['Time'];
                                      
                                      
$anterior['Score']   =  $dataGames['Score'];
                                      
                                     
// error_log("TICKETS EN SEGUNDO IF: Juego# ".$anterior['NumGame']." - ".$counterTickets);
                                
}else{   
                                      
$todayFigure += $counterWinLoss;
                                      
//error_log("TICKETS EN TERCER IF: Juego# ".$anterior['NumGame']." - ".$counterTickets);
                                      
$response .= "<tr>
                                                     <td>$anterior[Time]</td>
                                                     <td>$anterior[NumGame]</td>
                                                     <td>$anterior[Teams]</td>
                                                     <td>$anterior[Score]</td>
                                                     <td><a href=\"#\" onClick=\"openInfoWager(this);\">$counterTickets</a></td>
                                                     <td>$counterRisk</td>
                                                     <td>$counterWinLoss</td>
                                                     <td>$todayFigure</td>
                                                    </tr>"
;
                                       
// Borrar el anterior.
                                       
unset($anterior);
                                     }       
                            }
                            
                        
// Si hay un aterior trabajamos con el. Esto se hace ciempre.
                            
if ( !isset($anterior) ){
                                
// Preparar las variables para la proxima ronda.
                                
$counterTickets     0;
                                
$counterRisk        0;
                                
$counterWinLoss     0;
                                
$conta 0;
                                
$IdGames            "";
                                
$anterior           $dataGames;
                            }
                        }
//end while