查询问题以获取每天多次重复的每周数据?

我有两个表格来显示每个注册员工的日常服务。其中一个表包含每个服务的当日服务,另一个表包含每个服务的每周服务,并且在此表中,每天总是有多个记录要显示,这是我的问题。

第一个表运行良好,我使用GROUP CONCact提取数据并按员工姓名分组,在正确的时间分割并显示没有问题。在第二张表中,解决方案似乎必须有所不同,因为在该表中,我需要按每位员工的姓名对数据进行分组,并同时按每周的每一天对数据进行分组。

这是我的第一张桌子的代码:

$result_usuario = "SELECT
    events.date AS semana,employees.id_employee AS idemp,employees.nome AS nome,GROUP_concat(employees.nome
        ORDER BY events.date,employees.nome,period) AS nome,GROUP_concat(customers.nome
        ORDER BY events.date,period) AS nome2,GROUP_concat(customers.id_customer
        ORDER BY events.date,period) AS id,GROUP_concat(customers.adress
        ORDER BY events.date,period) AS address,GROUP_concat(customers.phone
        ORDER BY events.date,period) AS phone,GROUP_concat(events.id_event
        ORDER BY events.date,period) AS idevent,GROUP_concat(events.price
        ORDER BY events.date,period) AS price,GROUP_concat(events.frequence
        ORDER BY events.date,period) AS freq,GROUP_concat(events.period
        ORDER BY events.date,period) AS period,GROUP_concat(events.date
        ORDER BY events.date,period) AS dia
FROM
    events
        INNER JOIN
    employees ON employees.id_employee = events.id_employee
        INNER JOIN
    customers ON customers.id_customer = events.id_customer
    WHERE WEEK(events.date)=WEEK(NOW()) and employees.id_employee=events.id_employee
GROUP BY semana
ORDER BY semana,nome ASC"

$resultado_dados = mysqli_query($link,$result_dados);

if(($resultado_dados) AND ($resultado_dados->num_rows != 0)){
?>
<div class="logo">
    <img src="../assets/img/Logo.png" alt = "logojjl" style="padding-bottom:8px;"><br>
    <a class="btn btn-primary btn-sm"  name="print" href="#" type="button">Week</a>
</div>
<p class="card-category" style="padding-left: 13px; padding-top: 8px;">Date: <?php echo date("m/d/y") ?></p>

<table class="table table-sm table-hover">
    <thead>
       <tr>
          <th>Employee</th>
          <th>Customer</th>
          <th>Customer</th>
          <th>Customer</th>
       </tr>
    </thead>
    <tbody>
        <?php
           while($row_usuario = mysqli_fetch_assoc($resultado_dados)){
              $id = explode(',',$row_usuario['id']);
              $cust = explode(',$row_usuario['nome2']);
              $phone = explode(',$row_usuario['phone']);
              $address = explode(',$row_usuario['address']);
              $idev = explode(',$row_usuario['idevent']);
              $price = explode(',$row_usuario['price']);
              $freq = explode(',$row_usuario['freq']);
              $date = explode(',$row_usuario['dia']);
              $period = explode(',$row_usuario['period']);

         ?>


        <tr>
            <td><?php echo $row_usuario["nome"]; ?></th>

            <?php 
            for($i=0; $i < count($cust); $i++ ) { 
            ?>        
            <td><a type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#visu" value="<?php echo $id[$i]; ?>"><?php echo $cust[$i]; ?></a>


            </td>

上面的代码完全可以满足我的每日视图需求,但是我找不到基于该代码的每周视图答案。我试图进行一些更改,但结果始终与我想要的相反。第一个表比较容易,因为显示的内容都在同一行上,我可以毫无问题地拆分记录,第二个表的问题在于,在一周的每一天要显示多个记录,并且每个记录必须链接到合适的员工。

有人能帮助我根据此代码找到解决方案吗?我可以在其中将每位员工的记录分组,并同时将这些记录按星期几分组?我需要考虑在一周的某天没有记录的可能性的情况,在这种情况下,表空间将为空,这也需要考虑。

starfoucs 回答:查询问题以获取每天多次重复的每周数据?

使用

WEEK(events.date) AS semana 

在您的选择代码中。

这将为您提供周号以进行分组和订购

功能可以选择一周的第一天。

本文链接:https://www.f2er.com/3163411.html

大家都在问