Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return field name

Status
Not open for further replies.
Sep 5, 2004
55
CH
Hi all

i use the script below to query a mysql db and write the result in table on a webpage

-----------------------------------------------------------

<html>
<head>
<title>Query Test</title>
</head>
<body bgcolor=#BEE7AD>
<link href=" rel="stylesheet" type="text/css"/>
<?php
$benutzer= "ea";
$passwort= "*****";
$db = "protection";
$link = mysql_connect ( "localhost", $benutzer, $passwort ) ;
if ( ! $link )
die ( " Keine Verbindung zum MY SQL Server!" );
mysql_select_db ( $db, $link )
or die ( " Konnte Datenbank \"$db\" nicht öffnen !:
".mysql_error() );
$ergebnis = mysql_query ( "SELECT * FROM mos_mosform_formdata_1 ORDER BY Datum ASC ");
$anzahl_reihen = mysql_num_rows ( $ergebnis );
print "<font color =#0000000><center><strong>Einsaetze der Swiss Protection Guard GmbH! </font></center></strong>";
print "<table border=1>\n";
while ( $datensatz=mysql_fetch_row( $ergebnis ) )
{
print "<tr>\n";

foreach ($datensatz as $feld )
print "\t<td><font color=#000000>$feld</td></font>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close ( $link);
print "<strong><center><font color=#EE82EE><a href=javascript:top.close()>Fenster schliessen</font></strong></center>";

?>
</body>
</html>
------------------------------------------------------------

now everything works fine, but how can i write out also the names of the fields, p.a. there is a field named "Einsatzort" and this shoud be shown as a header over the table?

many thanks for your help

and happy new year
 
Something like this?
Code:
print "<table border=1>\n";
[red]$len = mysql_num_fields($ergebnis);
for ($i=0; $i<$len; $i++)
  print "<th>" . mysql_field_name($ergebnis, $i) . "</th>\n";[/red]

while ( $datensatz=mysql_fetch_row( $ergebnis ) )
    {
    print "<tr>\n";

        foreach ($datensatz as $feld )
        print "\t<td><font color=#000000>$feld</td></font>\n";
    print "</tr>\n";
    }
 print "</table>\n";

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top