title: Pulling Data in PHP from SQL Server
body: <p>I have an issue with my script somewhere but do not know exactly where it is incorrect.  Here is the code:</p>
  
  <pre><code>&lt;title&gt;Log&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;h1&gt; Log &lt;/h1&gt;
  
  &lt;form method="get" action="getlog.php"&gt; 
  
  &lt;table width="300" border="0"&gt;
    &lt;tr&gt;
      &lt;td&gt; Forte ID:&lt;/td&gt;
      &lt;td&gt;&lt;select id="ForteID" name="ForteID"&gt;                    
                      &lt;option value="nc4682"&gt;nc4682&lt;/option&gt;
                      &lt;option value="bs1441"&gt;bs1441&lt;/option&gt;
                      &lt;option value="sp3212"&gt;sp3212&lt;/option&gt;                 
          &lt;/select&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
   &lt;input type="submit" name="getLog" value="Get Log"&gt;
   &lt;/form&gt; 
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
  /*print_r($_POST);*/
  $serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
  $connectionInfo = array('Database'=&gt;'cslogs', 'UID'=&gt;'cslogslogin', 'PWD'=&gt;'123456');
  $connection = sqlsrv_connect($serverName, $connectionInfo);
  
  $query = 'SELECT    ForteID, Disposition, appNumber, Finance_Num, Num_Payments, ACH_CC,     Notes from logs';
  
  $result = sqlsrv_query($connection,$query);
  
  if (!$result) 
  {
      $message = 'ERROR: ' . sqlsrv_errors();
      return $message;
  }
  else
  {
      $i = 0;
      echo '&lt;html&gt;&lt;body&gt;&lt;table&gt;&lt;tr&gt;';
      while ($i &lt; sqlsrv_num_rows($result))
      {
          $meta = sqlsrv_fetch($result, $i);
          echo '&lt;td&gt;' . $meta-&gt;name . '&lt;/td&gt;';
          $i = $i + 1;
      }
      echo '&lt;/tr&gt;';
  
      while ( ($row = sqlsrv_fetch_array($result))) 
      {
          $count = count($row);
          $y = 0;
          echo '&lt;tr&gt;';
          while ($y &lt; $count)
          {
          $c_row = current($row);
          echo '&lt;td&gt;' . $c_row . '&lt;/td&gt;';
          next($row);
          $y = $y + 1;
      }
      echo '&lt;/tr&gt;';
  }
  sqlsrv_free_stmt ($result);
  
  echo '&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;';
  }
  sqlsrv_close( $connection);
  ?&gt;
  </code></pre>
  
  <p>And this is what I get in result, no matter what is selected in the drop down box and hit the button get log.</p>
  
  <p>nc4682  nc4682  Save    Save    asdf    asdf    fdas    fdas    1   1   cc  cc  asdf    asdf
  bs1441  bs1441  LOC LOC AN00336862  AN00336862  None    None    0   0   ach ach Backout Backout
  nc4682  nc4682  Save    Save    AN00336862  AN00336862  easdf   easdf   2   2   ach ach asdf    asdf
  sp3212  sp3212  Sale    Sale    NCXXXXXX1   NCXXXXXX1   none    none    1   1   cc  cc  asdfasdfasdf    asdfasdfasdf</p>
  
  <p>Each column is duplicated.  There are supposed to be 7 columns.</p>