title: Formatting output data into tables based on results
body: <p><strong>Figured it out, solution below!</strong></p>
  
  <p>I have an HTML table that is being populated by data from a database with two tables using the following structure:</p>
  
  <pre><code>Table 1:
  ------------------------------
  |id|data|other_data|more_data|
  ------------------------------
  
  Table 2:
  --------------------------------
  |id|entryId|fileType|other_data|
  --------------------------------
  </code></pre>
  
  <p>I'm joining these two tables similarly:</p>
  
  <pre><code>SELECT * FROM table1 LEFT JOIN table2 ON table2.entryId = table1.id
  </code></pre>
  
  <p>Sample return:</p>
  
  <pre><code>------------------------------------------------------------
  |id|data|other_data|more_data|id|entryId|fileType|other_data|
  -------------------------------------------------------------
  |1 |....|..........|.........|1| 1      |file1   |..........|
  |1 |....|..........|.........|2| 1      |file2   |..........|
  |2 |....|..........|.........|3| 2      |file1   |..........|
  |2 |....|..........|.........|4| 2      |file2   |..........|
  |3 |....|..........|.........|5| 3      |file1   |..........|
  |4 |....|..........|.........|6| 4      |file2   |..........|
  </code></pre>
  
  <p>For each case, I am expecting at least one result, usually two which I would like to sort based on the <code>fileType</code> field. fileType can either be <code>file1</code> or <code>file2</code>.</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;file1 data here&lt;/td&gt;
  &lt;td&gt;file 2 data here&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>If there is no file1 or file 2 in the result, insert a dash (-), but always keep that table structured in the same way, and in the same order. How can I accomplish this? I tried a simple if/else construct, but my logic is wrong and returns the data out of order; I'm having trouble wrapping my head around a working solution.</p>
  
  <pre><code>while(docs.next) {
  
  if(docs.getString("fileType").equals("file1")) {
          .....&lt;td&gt;file 1 data&lt;/td&gt;
      }
  
  else if(docs.getString("fileType").equals("file2")){
          .....&lt;td&gt;file 2 data&lt;/td&gt;
      }
  }
  </code></pre>
  
  <p>As always, your help is greatly appreciated!</p>
  
  <p><em><strong></em>**Figured it out, thanks! Solution:</strong></p>
  
  <p>I broke the logic into two queries then used what you suggest: 
   - first query grabs data from table1, sets up HTML table
   - set two variables(fileData1, fileData2) null
   - second query grabs data from table2, loops through the results to find matches and changes the actual value if the result exists
   - after loop, print table cells with results**</p>