Re: Getting Field Names in Microsoft SQL

From: Date: Sat, 17 Aug 2002 02:34:32 +0000
Subject: Re: Getting Field Names in Microsoft SQL
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-15319@lists.php.net to get a copy of this message
"R.S. Herhuth" <ronherhuth@pop.mindspring.com> wrote in message news:3D5CA43A.FF39E808@pop.mindspring.com... > > I'm trying to build a dynamic script that basically extracts all of the > fields in a MS SQL database...I just can't seem to figure out how to get > at the field names themselves. I am using the mssql_fetch_array > followed by the $row['field_name'] in an array. But I would like to > make the field_name dynamic (i.e. not knowing the field_names ahead of > time) which would make the script adaptable to any table in the > database. So if I get the field's value by $row['field_name'] how do I > get at the field's name? > > thanks, > Ron Hey. The best way to go about getting the name of fields in any given table is this: (connection to database assumed) <?php $query = select * from table; $fields = mssql_num_fields ($query); echo "<table border=\"1\">\n"; echo "<tr>\n"; for ($a = 1; $a < $fields; $a++) { echo "<td>" . mssql_field_name ($a) . "</td>\n"; } echo "</tr>\n"; echo "</table>\n"; ?> Hope this helps, I've just converted how I do it in MySQL to the functions for mssql. Brad

« previous php.windows (#15319) next »