title: Display MSSQL select data in php table
body: <p>I am missing something simple I am sure. This is the first time I am pulling data from a MSSQL server and displaying it in a table using php. I have done this in the past with mysql, but cannot get it to work with mssql. Here is my current code:</p>
  
  <pre><code>&lt;?php
   $myServer = "server";
   $myUser = "user";
   $myPass = "password";
   $myDB = "mssqldb"; 
  
   //connection to the database
   $dbhandle = mssql_connect($myServer, $myUser, $myPass)
       or die("Couldn't connect to SQL Server on $myServer"); 
  
   //select a database to work with
        $selected = mssql_select_db($myDB, $dbhandle)
            or die("Couldn't open database $myDB"); 
  
   //declare the SQL statement that will query the database
       $query = "SELECT col1, col2 ";
       $query .= "FROM sqltable ";
  
   //execute the SQL query and return records
       $result = mssql_query($query)
           or die('A error occured: ' . mysql_error());
  
   //Show results in table
  
   $o = '&lt;table id="myTable"&gt;
           &lt;thead&gt;
           &lt;tr&gt;
           &lt;th&gt;Col 1&lt;/th&gt;
           &lt;th&gt;Col 2&lt;/th&gt;
           &lt;/tr&gt;
           &lt;/thead&gt;&lt;tbody&gt;';
  
        while ( $record = mssql_fetch_array($result) )
            {
                $o .= '&lt;tr&gt;&lt;td&gt;'.$col1.'&lt;/td&gt;&lt;td&gt;'.$col2.'&lt;/td&gt;&lt;/tr&gt;';
            }               
  
         $o .= '&lt;/tbody&gt;&lt;/table&gt;';
  
         echo $o;
  
      //Show result from sql table separated by comma (commented out)
         /* while ( $record = mssql_fetch_array($result) )
          {
              echo $record["col1"] . " , " . $record["col2"] . "&lt;br /&gt;";
          } */
  
      //free result set memory
          mssql_free_result($result);
  
      //close the connection
          mssql_close($dbhandle);
      ?&gt;
  </code></pre>