Richard Lloyd
asked on
Create HTML table with data from any query using sqlsrv
Hi
I am trying to create a piece of code to display the contents of a query in a table, using php, sqlserver and sqlsrv_query.
I can build the body if the table, but the headers are not quite so easy. I don't believe that there is such a command as sqlsrv_fetch_field like the old mssql_fetch_field commend.
my code so far is...
//retrieve data from query...
$fields_num = mysql_num_fields($result);
echo "<table><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = sqlql_fetch_field($result) ;
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
while($row = sqlsrv_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
This produces the table body, but leaves the column names in the first row blank.
I'd appreciate any help!
thank you
I am trying to create a piece of code to display the contents of a query in a table, using php, sqlserver and sqlsrv_query.
I can build the body if the table, but the headers are not quite so easy. I don't believe that there is such a command as sqlsrv_fetch_field like the old mssql_fetch_field commend.
my code so far is...
//retrieve data from query...
$fields_num = mysql_num_fields($result);
echo "<table><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = sqlql_fetch_field($result)
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
while($row = sqlsrv_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
This produces the table body, but leaves the column names in the first row blank.
I'd appreciate any help!
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.