Re: PHP 4.1.1 - MSSQL 8

From: Date: Fri, 08 Feb 2002 14:52:57 +0000
Subject: Re: PHP 4.1.1 - MSSQL 8
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-11914@lists.php.net to get a copy of this message
Try this below for getting columns. This is a full EXAMPLE. I usually use a database object that wraps all these functions so that I can use same object to interchange between MSSQL and MySQL. But below is a starter example that you can use to see how it works. ============================================ ## assuming you are already connected, then do this: $query = "select * from users"; $result = mssql_query($query); if ( $result != 0 ) { $numrows = mssql_num_rows($result); if ( $numrows > 0 ) $numfields = mssql_num_fields($result); $table = "<table>"; $table .= "<tr>"; # this line will display column names for( $i=0 $i < $numfields; $i++ ) { $columnName = mssql_field_name( $result, $i ); $table .= "<td><b>" . $columnName . "</b></td>"; # the column rows; } $table .= "</tr>"; # this line displays all the row data while( $row = mssql_fetch_array($result) ) $table .= "<tr>"; # starts a new row for( $i=0 $i < $numfields; $i++ ) { $table .= "<td>" . $row[$i] . "</td>"; # this line is one cell of the data of row; the loop generates the whole record } $table .= "</tr>"; # ends the row } $table .= "</table>"; # the table is complete echo $table; # print out the table } else { echo "The query was successful, but no data was returned. <br>"; } } else { echo "Error running query: $query <br>"; } ============================================ Good luck, Nicole Amashta www.aeontrek.com ---------------------------------- "Chris" <tometerlaks@hotmail.com> wrote in message news:20020208081415.19301.qmail@pb1.pair.com... > I can get my tables from my DB but how can i get column names displayed > above the result? > > Chris > >

« previous php.windows (#11914) next »