Group values in a PHP Mysql query

0

I am pulling BD values into a table with the query results, this search is by date, it works perfectly if I fetch for a single day, however I would like when to fetch for two or more days (ex 07/06 / 2018 to 08/06/2018), it would bring the grouped (compiled) values of the query days, today it brings up the values by skipping lines and not grouping them;

code:

The sql:

$sql = "SELECT * FROM reporte_producao WHERE data_reporte BETWEEN '$data_ida' AND '$data_volta' AND turno = '$turno' AND grupo = '$v' ORDER BY id ASC";

to generate the table:

    foreach($num_array as $k => $v){

  ?>  
  <tr>
    <td><?php echo $num_array[$k]; ?></td>
    <td><?php echo $maq_array[$k]; ?></td>
    <td><?php echo $grupo_arr[$k]; ?></td>
    <td><?php echo $producao_array[$k]; ?></td>
    <td><?php echo (($producao_array[$k]) * 2); ?></td>
    <td><?php echo $segunda_array[$k]; ?></td>
    <td><?php echo $terceira_array[$k]; ?></td>
    <td><?php echo $producao_r_array[$k]; ?></td>
    <td><?php echo (($producao_r_array[$k])*2); ?></td>
    <td><?php echo $eficiencia_array[$k]."%"; ?></td>
  </tr>
  <?php } //fecha foreach

The most efficient way to do this would be below? Any suggestions?

$producao         += $data['producao'];
    
asked by anonymous 08.06.2018 / 15:44

1 answer

0

You need to do group by date:

SELECT
    *
FROM
    reporte_producao
WHERE
    data_reporte BETWEEN '$data_ida'
AND '$data_volta'
AND turno = '$turno'
AND grupo = '$v'
GROUP BY
    date_format(data_reporte, '%d/%m/%Y')
ORDER BY
    id ASC
    
08.06.2018 / 15:46