I have a $servicos
variable that receives the list of services registered in the DB through this code.
$query_servicos = "SELECT * FROM servicos ORDER BY nome ASC";
$result_servicos = mysqli_query($conectar, $query_servicos);
$servicos = array();
while ($linhas_servicos = mysqli_fetch_assoc($result_servicos)){
$servicos[] = $linhas_servicos['nome'];
}
$servicos = implode( ' ', $servicos);
I need to separate the data to list them and make a query.
$buscatotala = "SELECT * FROM dia WHERE dia='$datec' AND func='Alex' AND servicos LIKE '%$servicos%'";
$resultado_totala = mysqli_query($conectar, $buscatotala);
$totala = mysqli_num_rows($resultado_totala);
// Preciso que essa parte se repita, preenchendo a tabela com os dados do funcionário.
echo "
<tr>
<td>".$servicos[]."</td>
<td>";
if ($totala != '0'){
echo "<font color='red'>";
}
echo $totala."</font></td>
</tr>";
so it could ease the code, why not repeat the query that lists the services, in the next employees.
EX: NEXT EMPLOYEE:
$buscatotali = "SELECT * FROM dia WHERE dia='$datec' AND func='Italo' AND servicos LIKE '%$servicos%'";
$resultado_totali = mysqli_query($conectar, $buscatotali);
$totali = mysqli_num_rows($resultado_totali);
echo "
<tr>
<td>".$servicos[]."</td>
<td>";
if ($totali != '0'){
echo "<font color='red'>";
}
echo $totali."</font></td>
</tr>";
Entire code for an employee (I am repeating the same code for other employees only by changing the ending of the $ with the corresponding initial letter to the employee):
<div class="accrodion-regular">
<div id="accordion3">
<div class="card my-0">
<div class="card-header1" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
<span class="fas mr-3 fa-angle-down"></span>Serviços
</button>
</h5>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion3" style="">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table no-wrap p-table">
<tbody>
<?php
$query_listserva = "SELECT * FROM servicos ORDER BY nome ASC";
$result_listserva = mysqli_query($conectar, $query_listserva);
while ($linhas_listserva = mysqli_fetch_assoc($result_listserva)){
$servicosa = $linhas_listserva['nome'];
$buscatotala = "SELECT * FROM dia WHERE dia='$datec' AND func='Alex' AND servicos LIKE '%$servicosa%'";
$resultado_totala = mysqli_query($conectar, $buscatotala);
$totala = mysqli_num_rows($resultado_totala);
echo "
<tr>
<td>".$servicosa."</td>
<td>";
if ($totala != '0'){
echo "<font color='red'>";
}
echo $totala."</font></td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>