note 98581 modified in function.odbc-fetch-row by danbrown

From: Date: Fri, 25 Jun 2010 13:36:16 +0000
Subject: note 98581 modified in function.odbc-fetch-row by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170419@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. <?php $Fields = odbc_num_fields($cur); print "<table border='1' width='100%'><tr>"; // Build Column Headers for ($i=1; $i <= $Fields; $i++){ printf("<th bgcolor='silver'>%s</th>", odbc_field_name( $cur,$i)); } // Table Body $Outer=0; while( odbc_fetch_row( $cur )){ $Outer++; print "<tr>"; for($i=1; $i <= $Fields; $i++){ printf("<td>%s</td>", odbc_result( $cur, $i )); } print "</tr>"; } print "</table>"; print "<b> Your request returned $Outer rows!</b>"; odbc_close( $cnx); ?> --was-- Thank you soo much for this man! You saved me soo much time, I had been looking for something just like this!!! 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. $Fields = odbc_num_fields($cur); print "<table border='1' width='100%'><tr>"; // Build Column Headers for ($i=1; $i <= $Fields; $i++){ printf("<th bgcolor='silver'>%s</th>", odbc_field_name( $cur,$i)); } // Table Body $Outer=0; while( odbc_fetch_row( $cur )){ $Outer++; print "<tr>"; for($i=1; $i <= $Fields; $i++){ printf("<td>%s</td>", odbc_result( $cur, $i )); } print "</tr>"; } print "</table>"; print "<b> Your request returned $Outer rows!</b>"; odbc_close( $cnx); http://php.net/manual/en/function.odbc-fetch-row.php

« previous php.notes (#170419) next »