Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

query problem to fetch weekly data with more than one recurrence per day?

$
0
0

I have two tables to display the daily services of each registered employee. One of the tables contains the current day services for each one, the other contains the weekly services of each one and in this table each day there is always more than one record to display, and this is my problem.

The first table works perfectly, I fetch the data using GROUP CONCACT and group by employee name, split at the correct times and display without problems. In the second table the solution seems to have to be different because in it I need to group the data by the name of each employee and at the same time group the data by each day of the week.

Here is my code for the first table:

$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, employees.nome, period) AS nome2,
        GROUP_CONCAT(customers.id_customer
        ORDER BY events.date, employees.nome, period) AS id,
        GROUP_CONCAT(customers.adress
        ORDER BY events.date, employees.nome, period) AS address,
        GROUP_CONCAT(customers.phone
        ORDER BY events.date, employees.nome, period) AS phone,
        GROUP_CONCAT(events.id_event
        ORDER BY events.date, employees.nome, period) AS idevent,
        GROUP_CONCAT(events.price
        ORDER BY events.date, employees.nome, period) AS price,
        GROUP_CONCAT(events.frequence
        ORDER BY events.date, employees.nome, period) AS freq,
        GROUP_CONCAT(events.period
        ORDER BY events.date, employees.nome, period) AS period,
        GROUP_CONCAT(events.date
        ORDER BY events.date, employees.nome, 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>

The code above does exactly what I need for the daily view, but I can't find an answer based on that code for the weekly view. I have tried to make some changes, but the results are always contrary to what I want. The first table is easier because the displayed content is all on the same line and I can split the records without problem, the problem with the second table is that on each day of the week there is more than one record to display and each record must be linked to the right employee.

Can anyone help me find a solution based on this code where I can group the records in each employee, and at the same time these records grouped by the days of the week? I need something that considers the possibility of no records at some day of the week, in which case the table space would be empty, this needs to be considered as well.


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>