title: How to loop through column in php mysql
body: <p>Wondering if someone can point me in the right direction.</p>
  
  <p>Currently I have a table with several columns with names such as A1, A2, A3 etc and I've found that doing it this way no longer works with the new database structure I want to use.</p>
  
  <p>The A1, A2, A3.. will now be listed within the actual column.</p>
  
  <p>I have included the current code I am, using to get this information, but I don't know how to loop through the column there the A1, A2.. are and get the information on the same row.</p>
  
  <p><strong>PHP Code:</strong></p>
  
  <pre><code>&lt;?php     
    $i=1;            
    $row = mysqli_fetch_assoc($result);    
    while ($i &lt; 6)    {
        if($row["A".$i.""]=='FREE')        {
            print "&lt;td&gt;&lt;p&gt;Available&lt;/p&gt;&lt;/td&gt;";
        }
        else {
                 if($row["A$i"]==$auth_user) {
                     echo $i;
                     print"&lt;td&gt;&lt;div align=\"center\"&gt;".$row["A". $i. ""];
                     print "&lt;br /&gt;&lt;p&gt;Cancel&lt;/p&gt;&lt;/span&gt;";
                     print "&lt;/div&gt;&lt;/td&gt;";
                 }
                 else {
                          print"&lt;td&gt;&lt;div align=\"center\"&gt;".$row["A". $i. ""];
                          print "&lt;/div&gt;&lt;/td&gt;";
                      }
             }
             $i++;
          }
      }
  ?&gt;
  </code></pre>
  
  <p>Any pointers would be great.</p>
  
  <p>Current Table Structure:</p>
  
  <pre><code>Date         | A1   |  A2   ...
  ---------------------------
  2017-05-23   | John |  FREE ...
  2017-05-24   | Jack |  FREE ...
  2017-05-25   | Jane |  John ...
  2017-05-26   | FREE |  Jack ...
  </code></pre>
  
  <p>New Table Structure:</p>
  
  <pre><code>Date         | Session   |  User ...
  ------------------------------------
  2017-05-23   | A1        |  John ...
  2017-05-23   | A2        |  Jane ...
  2017-05-23   | A4        |  John ...
  2017-05-23   | A9        |  Jack ...
  </code></pre>