note 3398 deleted from odbc_fetch_row by ronabop

From: Date: Fri, 11 Aug 2000 15:46:09 +0000
Subject: note 3398 deleted from odbc_fetch_row by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-1211@lists.php.net to get a copy of this message
Here is code snippet to do dynamically build a table so you do not have to hardcode the fields that you wish to display. You could use the the odbc_result_all but this allows special handling of rows/columns. This is similar to some ASP code I use and this is my first PHP page so I hope it is useful..... //Get number of fields $Fields = odbc_num_fields($cur); //Start your table print "<table border='1' width='100%'><tr>"; // Build Column Headers for ($i=1; $i <= $Fields; $i++){ $name=odbc_field_name($cur , $i); print "<th>$name</th>"; } //Loop thru result set and build rest of table $Outer=0; while( odbc_fetch_row( $cur )){ $Outer++; print "<tr>"; $i=1; while($i <= $Fields){ //Here you can add contional stuff for formatting row or field values $Value=odbc_result( $cur, $i ); print "<td>$Value</td>"; $i++; } print "</tr>"; } print "</table>"; print "<b>The query returned $Outer rows!</b>"; odbc_close( $cnx); Hope this helps someone.

« previous php.notes (#1211) next »