<?php
$conn=new mysqli('localhost','root','','routine');
$sql = $conn->query("SELECT DISTINCT(day) FROM `rt`");
while($row = $sql->fetch_assoc()){

  $day = $row['day'];
  $sql2 = $conn->query("SELECT DISTINCT(batch) FROM `rt` WHERE day = '$day' ORDER BY batch ASC");
  while ($r = $sql2->fetch_assoc()) {
    $batch = $r['batch'];

    $student = null;
    $sql3 = $conn->query("SELECT sid FROM `rt` WHERE day = '$day' AND batch = '$batch'");
    while($id = $sql3->fetch_assoc()){
      $sid = $id['sid'];
      $name = $conn->query("SELECT name FROM `student_name` WHERE sid=" . $sid)->fetch_assoc()['name'];
      echo '<pre>';echo " day: " . $day. "  Batch: ". $batch."  Name: ". $name;;
      $student[] = ['id' => $sid, 'name'=> $name ];
    }
    $batches[$batch] = $student;
  }
  $data[$day] =$batches;
}
  echo '<pre>';
print_r ($data);





?>


<!-- <!DOCTYPE html> -->
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    table,
    th,
    td {
        border: 2px solid;
        margin: auto;
        border-collapse: collapse;
        width: 1300px;
        height: 30px;
    }
    </style>
</head>

<body>
    <table class="table">
        <tr>
            <th>Day</th>
            <th>sn</th>
            <th>Batch 1<br> (10.30-12.00)</th>
            <th>Batch 1<br> (12.00-1.30)</th>
            <th>Batch 1<br> (1.30-3.00)</th>

            <?php
        $days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
        for($d = 0; $d < count($days); $d++){
            $day = $days[$d];
           
            echo '<tr>';
            echo '<td height="150px">'.strtoupper(date('l', strtotime($day)))."</td>";
            for($x = 1; $x <= 5; $x++){
                echo '<td width="250px" valign="top">';
                if(isset($data[$day])){
                    if(isset($data[$day][$x])){
                        for($i = 0; $i < count($data[$day][$x]); $i++){
                            echo '<strong>'.$data[$day][$x][$i]['name']. '</strong><font color="red">{'. $data[$day][$x][$i]['id'] . '}</font><br/>';
                        }
                    }
                }
                echo '</td>';
            }
            echo '</tr>';
        }
        ?>
        </tr>

    </table>

Post a Comment

Previous Post Next Post