"SELECT *, SUM(price) as sum FROM TotalTickets GROUP BY email"
<table class="table email">
<thead>
<tr>
<th>Название</th>
<th>Дата</th>
<th>Начало</th>
<th>Цена</th>
<th>Сумма</th>
</tr>
</thead>
<tbody>
<?php
// подключение к бд
include('../connection.php');
// достаем все новости
$sql = mysql_query("SELECT *, SUM(price) as sum FROM TotalTickets GROUP BY email") or die(mysql_error());
while($cust = mysql_fetch_array($sql, MYSQL_ASSOC)){
echo '<tbody class="labels">
<tr>
<td colspan="5">
<label for="accounting">'.$cust['email'].'</label>
<input type="checkbox" name="accounting" id="accounting" data-toggle="toggle">
</td>
</tr>
</tbody>
<tbody class="hide">
<tr>
<td>'.$cust['filmName'].'</td>
<td>'.$cust['date'].'</td>
<td>'.$cust['timeBegin'].'</td>
<td>'.$cust['price'].'</td>
<td>'.$cust['sum'].'</td>
</tr>
</tbody> ';
}
?>
</tbody>
</table>
$sql = mysql_query("SELECT * FROM TotalTickets ORDER BY email ASC") or die(mysql_error());
$cust_email = false; $cust_txt = ""; $cust_sum = 0;
while($cust = mysql_fetch_array($sql, MYSQL_ASSOC))
{
if ($cust_email !== false AND $cust_email != $cust['email'])
{
echo '<tbody class="labels">
<tr>
<td colspan="5">
<label for="accounting">'.$cust_email.': '.round($cust_sum, 2).'</label>
<input type="checkbox" name="accounting" id="accounting" data-toggle="toggle">
</td>
</tr>
</tbody>
<tbody class="hide">
'.$cust_txt.'
</tbody> ';
$cust_email = $cust['email'];
$cust_txt = "";
$cust_sum = 0;
}
$cust_sum += $cust['price'];
$cust_txt .= ' <tr>
<td>'.$cust['filmName'].'</td>
<td>'.$cust['date'].'</td>
<td>'.$cust['timeBegin'].'</td>
<td>'.$cust['price'].'</td>
<td>0</td>
</tr>';
}
if (!empty($cust_txt))
{
echo '<tbody class="labels">
<tr>
<td colspan="5">
<label for="accounting">'.$cust_email.': '.round($cust_sum, 2).'</label>
<input type="checkbox" name="accounting" id="accounting" data-toggle="toggle">
</td>
</tr>
</tbody>
<tbody class="hide">
'.$cust_txt.'
</tbody> ';
}