Group data related to a column

0

I'm having trouble grouping schedules by date.

I have a table in html that is populated from an sql query. The idea would be to list in a column the date and in the other column all the schedules referring to that date without having to jump line like in the photo that I posted at the end. What could be done?

Code:

<table class="table table-striped">
   <thead>  
      <tr>
    <th>Data</th>
    <th>Marcações</th>          
      </tr>
  </thead>   
<?php

$con = mysql_connect($host, $user, $pass) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($db, $con);

$sql= mysql_query("SELECT dia, hora FROM marcacoes");
    while($exibe = mysql_fetch_assoc($sql)){

    $tabela ='<tbody>'; 
    $tabela .='<tr>';
    $tabela .='<td>'.date("d-m-Y", strtotime($exibe['dia'])).'</td>'; 
    $tabela .='<td>'.$exibe['hora'].'</td>';
    $tabela .='</tr>';
    $tabela .='</tbody>';

    echo $tabela;

    }   
?>

Problem example:

    
asked by anonymous 05.07.2016 / 13:28

1 answer

1

An example in MySQL would be the GROUP_CONCAT that concatenates a column, with value in N rows in a single column and a row, as long as the GROUP BY clause is used in the other non-collation columns, as shown below:

SELECT data, GROUP_CONCAT(hora) As horarios FROM 'marcacoes' GROUP BY data;

In this case you would retrieve the values of the 'date' and 'time' columns in your code to display the information returned by SELECT.

I hope I have helped.

    
05.07.2016 / 13:36