title: How to use for loop to display day and time using php?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>echo "&lt;table class='hoverTable'  cellpadding=10 border=0 align=center style='border-collapse:collapse;width:500px'&gt;&lt;tr  style='color:#FFF;background-color:#000; font-size:20px'&gt;&lt;td align=center&gt;Date&lt;/td&gt;&lt;td align=center&gt;Time&lt;/td&gt;&lt;td align=center colspan=2 &gt;Status&lt;/td&gt;&lt;/tr&gt;";
   for($k=1;$k&lt;=7;$k++)
   {
    if($k==1)
     $day='Monday';
    else if($k==2)
     $day='Tuesday';
    else if($k==3)
     $day='Wednesday';
    else if($k==4)
     $day='Thursday';
    else if($k==5)
     $day='Friday';
    else if($k==6)
     $day='Saturday';
    else 
     $day='Sunday';
    for($i=8; $i&lt;17;$i++)
    {
     $time="$i:00";
     $j= $time+1;
     $endtime="$j:00";
  
     $sql=mysqli_query($con,"SELECT * FROM (SELECT TT_ID,TT_Subject FROM timetable WHERE TT_Day='$day' and L_ID='00106') AS TAB_1, (SELECT TT_ID,TT_Subject FROM timetable WHERE TT_Time='$time' OR TT_Endtime='$endtime') AS TAB_2 WHERE TAB_1.TT_ID = TAB_2.TT_ID ");
     if(mysqli_num_rows($sql)&gt;0)
     {
      $rows=mysqli_fetch_assoc($sql);
      $sub=$rows['TT_Subject'];
      $runsql=mysqli_query($con,"SELECT * FROM subject WHERE S_Code='$sub'");
      {
       $result=mysqli_fetch_assoc($runsql);
       $subname=$result['S_Name'];
       echo "&lt;tr bgcolor='#F5F6CE'&gt;&lt;td&gt;".$day."&lt;/td&gt;&lt;td align=center style='font-size:15px; width:100px; color:#FF0000;'&gt;".$time." - ".$endtime."&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td align='center' style='font-size:15px; height:40px; color:#FF0000;' title='Subject: $subname'  &gt;Not Available&lt;/td&gt;   ";             
      }
     }
     else
      echo "&lt;tr bgcolor='#F5F6CE'&gt;&lt;td&gt;".$day."&lt;/td&gt;&lt;td align=center style='font-size:15px; width:100px; color: #0000FF;'&gt;".$time." - ".$endtime."&lt;/td&gt;&lt;td style='width:10px;'&gt;:&lt;/td&gt;&lt;td align='center' style='font-size:15px; height:40px;'&gt;&lt;a href='add_timetable.php'&gt;Available&lt;/a&gt;&lt;/td&gt;";      
    }
    echo "&lt;/tr&gt;";
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want to use looping to display the data in database. I success display data but the interface is not I wanted (the table that have color) . Can you please teach me how to display the table like the image below?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
   echo "&lt;table class='hoverTable'  cellpadding=10 border=0 align=center style='border-collapse:collapse;width:500px'&gt;&lt;tr  style='color:#FFF;background-color:#000; font-size:20px'&gt;&lt;td align=center&gt;Date&lt;/td&gt;&lt;td align=center&gt;Time&lt;/td&gt;&lt;/tr&gt;";
   for($k=1;$k&lt;=7;$k++)
   {
    if($k==1)
     $day='Monday';
    else if($k==2)
     $day='Tuesday';
    else if($k==3)
     $day='Wednesday';
    else if($k==4)
     $day='Thursday';
    else if($k==5)
     $day='Friday';
    else if($k==6)
     $day='Saturday';
    else 
     $day='Sunday';
    
  
    for($i=8; $i&lt;17;$i++)
    {
     $time="$i:00";
     $j= $time+1;
     $endtime="$j:00";
     echo "&lt;tr bgcolor='#F5F6CE'&gt;&lt;td&gt;".$day."&lt;/td&gt;&lt;td align=center style='font-size:15px; width:100px; color: #0000FF;'&gt;".$time." - ".$endtime."&lt;/td&gt;&lt;/tr&gt;";      
    }
   
   }
   
  ?&gt;</code></pre>
  </div>
  </div>
  
  <a href="https://i.stack.imgur.com/IggBF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IggBF.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/gc3XU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gc3XU.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/g8gKW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g8gKW.png" alt="enter image description here"></a></p>