title: How to create a timetable in php
body: <p>I want to create a student time table having 5 subject, 5 teacher, 5 class, per day 5 hour and 5 day in a week. I have completed everything, but now the issue I am facing is if there is no data inserted for specific one day (suppose for Monday there is no class) and i am inserting data for Tuesday. Then the Tuesday data are showing on Monday.</p>
  
  <p>Here's some images:</p>
  
  <p>Output TimeTable(Here the No Class field's time is 2pm-3pm and day is Thursday. But it is showing in Friday and in 10am-11am)</p>
  
  <p><img src="https://i.stack.imgur.com/u38oN.jpg" alt=""></p>
  
  <p>My TimeTable database table</p>
  
  <p><img src="https://i.stack.imgur.com/Sau8v.jpg" alt=""></p>
  
  <p>I want to show if there is no row inserted for a day. Then for that day data should be show as 'No Class' in front end time table.
  Here I am placing my logic:</p>
  
  <pre><code>   &lt;body&gt;
      &lt;?php include 'sidenav.php';?&gt;
      &lt;article&gt;
          &lt;table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" &gt;
                &lt;tr&gt;
                  &lt;th&gt;&lt;b&gt;TIME&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Monday&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Tuesday&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Wednesday&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Thursday&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Friday&lt;/b&gt;&lt;/th&gt;
                &lt;/tr&gt;
              &lt;tbody&gt;
                  &lt;h1&gt;Class Wise Time Table&lt;/h1&gt;
                  &lt;?php
                      error_reporting(1);
                      session_start();
                      if ((isset($_SESSION['login'])) &amp;&amp; (isset($_REQUEST['cls']))) {
                          $classname = $_REQUEST['cls'];
                          $conn = mysqli_connect("localhost", "root", "", "finaltask");
                          $sql = "select DISTINCT (time) as time from time_table where classname = "."'$classname'";
                          $rest = mysqli_query($conn, $sql);
                          while($t = mysqli_fetch_assoc($rest)){
                          $sql = "select * from time_table where classname = "."'$classname'". " AND time = '".$t['time']."'";
                          //print_r($sql);exit;
                          $res = mysqli_query($conn, $sql);
                          while($row = mysqli_fetch_assoc($res)){
                              //echo '&lt;pre&gt;'; print_r ($row);
                              if(($row['day']=='Monday')&amp;&amp;($row['time']==$t['time'])){
                                  echo"&lt;tr&gt; &lt;td&gt;{$row['time']}&lt;/td&gt;";
                                  if(($row['subject']==' ')&amp;&amp;($row['teacher']== ' ')){
                                      echo "&lt;td&gt;No Class&lt;/td&gt;";//die('');
                                  }else{
                                      echo  "&lt;td&gt;".$row['subject']."&lt;br&gt;".$row['teacher']."&lt;/td&gt;";
                                  }
                              }
                              if(($row['day']=='Tuesday')&amp;&amp;($row['time'])){
                                  if(($row['subject']=='')&amp;&amp;($row['teacher']=='')){
                                  echo "&lt;td&gt;No Class&lt;/td&gt;";
                                  }else{
                                      echo  "&lt;td&gt;".$row['subject']."&lt;br&gt;".$row['teacher']."&lt;/td&gt;";
                                  }
                              }
                              if(($row['day']=='Wednesday')&amp;&amp;($row['time'])){
                                  if(($row['subject']=='')&amp;&amp;($row['teacher']=='')){
                                  echo "&lt;td&gt;No Class&lt;/td&gt;";
                                  }else{
                                      echo  "&lt;td&gt;".$row['subject']."&lt;br&gt;".$row['teacher']."&lt;/td&gt;";
                                  }
                              }
                              if(($row['day']=='Thurshday')&amp;&amp;($row['time'])){
                                  if(($row['subject']=='')&amp;&amp;($row['teacher']=='')){
                                  echo "&lt;td&gt;No Class&lt;/td&gt;";
                                  }else{
                                      echo  "&lt;td&gt;".$row['subject']."&lt;br&gt;".$row['teacher']."&lt;/td&gt;";
                                  }
                              }
                              if(($row['day']=='Friday')&amp;&amp;($row['time'])){
                                  if(($row['subject']=='')&amp;&amp;($row['teacher']=='')){
                                  echo "&lt;td&gt;No Class&lt;/td&gt;";
                                  }else{
                                      echo  "&lt;td&gt;".$row['subject']."&lt;br&gt;".$row['teacher']."&lt;/td&gt;&lt;/tr&gt;";
                                  }
                              }
                          }
                        }
                      }        
                  ?&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
  </code></pre>