直接从db表中获取字段名称[关闭]

I’m building a database driven website using WAMP

I have database with table called userinfo with the following field names DateTime DomainName ComputerName UserName NetworkSettings.

And I have a PHP script with a HTML table

echo "<div id='tableheading'>
";
echo "<table class='data' border='1'align='center'>
";
echo "<tr>
";

echo "<th> DateTime </th>
echo "<th> DomainName </th>
echo "<th> ComputerName </th>
echo "<th> UserName </th>
echo "<th> NetworkSettings </th>

How do I get the field names straight from the database?

As you are using WAMP, I assume you're talking about MySQL. Have a look at mysqli_result::fetch_fields().

I'd advise against that

  1. It's better to give field names plain lowercase names
  2. HTML table headers often mismatch db table field names
  3. Typing field names by hand is not as hard as you imagine