title: php - Adding a link to my SQL query table
body: <p>I currently have a functioning table displaying on my website using the following query/table display. I need to modify how the table is displayed so I can make the final column a link based on their CompanyID I call in the query.</p>
  
  <p>Query (sanitized for security):</p>
  
  <pre><code>$tableResults = dbQuery('SELECT CompanyName, ContractStatus, LEFT(ContractDate, 10), CCNumber, LevelName, cinfo.CompanyID 
  FROM &lt;databases&gt; WHERE &lt;things&gt;
  order by CompanyName');
  
  while($tableRow = mysql_fetch_assoc($tableResults))
  {
      $tableData[] = $tableRow;
  }
  
  $tableColNames = array_keys(reset($tableData));
  </code></pre>
  
  <p>And the table (ignore the formatting, the data structure is my concern):</p>
  
  <pre><code>&lt;table width="100%" border="0" cellspacing="1" cellpadding="5" class="tablesorter" id="contcomm_table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th class="header"&gt;&lt;strong&gt;Company Name&lt;/strong&gt;&lt;/th&gt;
              &lt;th class="header"&gt;&lt;strong&gt;Contract Status&lt;/strong&gt;&lt;/th&gt;
              &lt;th class="header"&gt;&lt;strong&gt;Contract Date&lt;/strong&gt;&lt;/th&gt; 
              &lt;th class="header"&gt;&lt;strong&gt;Writing Number&lt;/strong&gt;&lt;/th&gt;
              &lt;th class="header"&gt;&lt;strong&gt;View Comm Schedule&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;?
      foreach($tableData as $row)
      {
          echo "&lt;tr&gt;";
          foreach($tableColNames as $colName)
          {
              echo "&lt;td&gt;" . $row[$colName] . "&lt;/td&gt;";
          }
          echo "&lt;/tr&gt;";
      }
  ?&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The link in question would be '/_Document.pdf'. I think I'm having a case of the Mondays, because I just can't grasp this right now.</p>
  
  <p>EDIT: The answers so far have gotten me closer, and now I just need to get over the last hump. I have everything displaying right, and the URL will show up... but now I need to concatenate the URL with the Company ID in the URL.</p>
  
  <p>So, the relevant area I'm working on now, along with my best efforts at it:</p>
  
  <pre><code>if ($colName=='LevelName') {
      echo "&lt;td&gt;&lt;a href='http://my.url.here/".$CompanyID."_Document.pdf' target='_blank'&gt;" . $row[$colName] . "&lt;/a&gt;&lt;/td&gt;";
  }
  else {
      echo "&lt;td&gt;" . $row[$colName] . "&lt;/td&gt;";
  }
  </code></pre>