Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

echoing each column from table twice problem

$
0
0

Hi. 

 

So I'm trying to echo out all the columns from the table. I'm connecting to SQL Server by the way. The number of columns in the table will vary so I want to loop and echo all the columns in the table without specifying. Its working but its echoing each column twice into the table. 

Any idea why this is? 

Thanks 





echo "<table border='1'>
<tr>
 <th>start</th>,<th>end</th>" . join('</th><th>', $cols) . "</th> </tr>";


$tsql = "SELECT * FROM MYtable
ORDER BY  start";

/* Execute the query. */

$result = sqlsrv_query( $conn, $tsql);

if ( $result )
{
     echo "Statement executed.<br>\n";
}
else
{
     echo "Error in statement execution.\n";
     die( print_r( sqlsrv_errors(), true));
}



while( $row = sqlsrv_fetch_array( $result))
{
  
 echo "<tr>";

foreach ($row as $field){
    echo "<td>".stripslashes($field)."</td>";
 }
  echo "</tr>";


}

echo "</table>";


Viewing all articles
Browse latest Browse all 13200

Latest Images

Trending Articles



Latest Images