Answer the question
In order to leave comments, you need to log in
How to load data from db for drop down table?
I have a table on the site, I need the data to be loaded from the database with a group by query, let's say it's like my email, and when you click on this email, the table opens and the data that is grouped appears. Now only the first element is loaded, how to load all?
"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>
Answer the question
In order to leave comments, you need to log in
The dumbest 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">
<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> ';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question