How to load data from dB to drop-down table?

I have a table on the website, you need to database data loaded by a query with group by, let's say as in my email, and when clicked on this email, unfolded the table and there is data that is grouped. Now only the first item is loaded, how to load all?
Screen
5cf92c50c8e00946709069.png
SQL
"SELECT *, SUM(price) as sum FROM TotalTickets GROUP BY email"
HTML
<table class="table email">
<thead>
the <tr>
<th>Name</th>
<th>date</th>
<th>Start</th>
<th>Price</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
 // connect to database
 include('../connection.php'); 
 // get all the news
 $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">
the <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">
the <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>
March 23rd 20 at 19:24
1 answer
March 23rd 20 at 19:26
Solution
The dubolomnyh option:
$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">
the <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">
the <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> ';
}

Find more questions by tags SQLPHP