title: PHP MYSQL Horizontal loop
body: <p>I'm making a php page to draw information from a mysql database, and before I get stuck too headlong into it I thought I'd see if there is an easier way to do what I'm doing.</p>
  
  <p>I have a MySql query that returns multiple rows, through which I can easily loop using a while loop and it will obviously loop through where there is relative "matching" data.  </p>
  
  <p>Each row that is pulled out can have between 1 and 16 columns of data that is different for each row, and the way I currently extracting valid information is hard coding "if" commands for each column so that only information that has been entered gets displayed, e.g:</p>
  
  <pre><code>if($column1 != ""){
      $output .= "&lt;div style='float: left;'&gt;Column 1 Stuff&lt;/div&gt;";
      }
  if($column2 != ""){
      $output .= "&lt;div style='float: left;'&gt;Column 2 Stuff&lt;/div&gt;";
      }
  </code></pre>
  
  <p>This works fine, but it isn't very dynamic and requires an update of the code if the Mysql Database Table expands, which it is.  What I'd really like to be able to do it use a single bit of code, like a while loop, that performs the same procedure for every column that has data in it and ignores any blank cells.  Is there a good way to achieve this efficiently that anyone knows of?</p>
  
  <p>Also, just in case it's a problem, my "div"s are all aligned left so that when they reach the end of their enclosing div they automatically wrap themselves to the next line neatly, so if there were 9 results there would be 3 rows of 3 "div" boxes.  Is this a valid way of achieving this kind of result?  I was looking into using a "break" command as with and answer in this post -> <a href="https://stackoverflow.com/questions/5002138/how-to-do-a-horizontal-looping-in-php">How to do a Horizontal looping in PHP</a>, but I've had so many compatibility issues with pre IE9  tags that I am avoiding implementing any more where possible.</p>
  
  <p>Thanks in advance your your help, if indeed you can! 
  Joe</p>