Código PHP:
Ver original<?php
// Funcion que muestra los datos.
function showFila(&$response, $anterior, $counterTickets, $counterRisk, $counterWinLoss, $todayFigure)
{
$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>";
}
// Variable
$estado = (bool) ($dataGames = $strDataGames->fetch(PDO::FETCH_ASSOC));
// El while
while($estado)
{
{
// Si hay un aterior trabajamos con el. Esto se hace ciempre.
$counterTickets += $anterior['Tickets'];
$counterRisk += $anterior['Risk'];
$counterWinLoss += $anterior['WinLoss'];
$IdGames .= $anterior['IdGame']."+";
// Verificamos la similitud con el anterior. Si coinciden hago lo que quiero.
if
( ($dataGames['NumGame'] == $anterior['NumGame'])
&& ($dataGames['Teams'] == $anterior['Teams'])
)
{
$anterior['Time'] = $dataGames['Time'];
$anterior['Score'] = $dataGames['Score'];
}
else
{
$todayFigure += $counterWinLoss; // Resto cuando el usuario perdio.
// ahora se usa la funcion
showFila($response, $anterior, $counterTickets, $counterRisk, $counterWinLoss, $todayFigure);
// Borrar el anterior.
}
}
{
// Preparar las variables para la proxima ronda.
$counterTickets = 0;
$counterRisk = 0;
$counterWinLoss = 0;
$IdGames = "";
$anterior = $dataGames;
}
// Si es el ultimo.
if(!($estado = (bool) ($dataGames = $strDataGames->fetch(PDO::FETCH_ASSOC))))
showFila($response, $anterior, $counterTickets, $counterRisk, $counterWinLoss, $todayFigure);
}