title: Importing headers and data into HTML table from SQL database
body: <p>In short, what I’ve been trying to implement over the last week or so is to retrieve data from an SQL table and insert it into specific columns of an HTML table. It’s been done, I know, I’ve browsed a bunch of forums, manuals, and videos but haven’t found anything that answers my problem. </p>
  
  <p>What I want to do is create a table such as the one below: </p>
  
  <p><img src="https://i.stack.imgur.com/FaSfH.png" alt="html table"></p>
  
  <p>A brief explanation is: A user inputs a date when they want to make an appointment. The SQL table retrieves both the user-selected date in addition to 3 days before and 3 days after the select date (in this case the user selected Wed, Dec 6-17). The header represents the day and the time slots below represent the available time slots that are bookable on that day (this goes up to 17:00). In the case that a time slot isn’t available it shouldn’t be shown there, rather it should be replaced by the next available time slot.  </p>
  
  <p>This is the (non-functioning) php code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  require 'connection.php';
  $conn = Connect();
  
  $sql1 = 'SELECT DATE_b FROM daysofweek';
  $query1 = mysqli_query($conn,$sql1);
  
  $sql2 = 'SELECT TIME FROM daysofweek';
  $query2 = mysqli_query($conn, $sql2);
  ?&gt;
  
  &lt;table class="bookAppointment"&gt;
    &lt;thead&gt;
        &lt;?php
        while ($row = mysqli_fetch_array($query1)) {
          echo '&lt;tr&gt;
                  &lt;th&gt;'.date('D, M d-y',strtotime($row['DATE_b']) ).'&lt;/th&gt;
                &lt;/tr&gt;';
          }
        ?&gt;
    &lt;/thead&gt;
        &lt;?php
        while ($row = mysqli_fetch_array($query2)){
          echo '&lt;tr&gt;
                  &lt;td&gt;'.$row['TIME'].'&lt;/td&gt;
                &lt;/tr&gt;';
          }
        ?&gt;
      &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And the result is that each header prints vertically (one under another) and I would like the headers to print horizontally.</p>
  
  <p>What has mostly been covered by other resources is that the table headers have to be fixed – as in not from the SQL database. However, in this case I also need these headers to be pulled from the database in addition to the time slots that belong to each date. </p>
  
  <p>Any help in this regard would be much appreciated. Even if it is just pointing me in the direction where I could read up more about how I could make php code do this or if this is an issue with the database design. </p>
  
  <p>Thanks in advance! </p>