$sql = mysql_query("select count(time(waktutranssaksi)) as jml from nama_table group by userid,date(waktutranssaksi) order by jml desc limit 1");
$count = mysql_fetch_array($sql);
$count = $count['jml'];
echo '</table>';
echo '<tr>';
echo '<td>userid</td>';
echo '<td>tanggal</td>';
for($i = 1; $i<=$count;$i++){
echo '<td>waktu'.$i.'</td>';
}
echo '</tr>';
$sql = mysql_query("select nama_table.*,group_concat(time(waktutranssaksi)) as timetransaksi,date(waktutranssaksi) as tgltransaksi from nama_table group by userid,date(waktutranssaksi)");
while($data = mysql_fetch_array($sql)){
echo '<td>'.$data['userid'].'</td>';
echo '<td>'.$data['tgltransaksi'].'</td>';
$waktu = explode(',', $data['timetransaksi']);
for($i=0;$i<$count;$i++){
echo '<td>'.(isset($waktu[$i]) ? $waktu[$i] : '').'</td>';
}
}
echo '</table>';