note 30697 added to function.odbc-field-name

From: Date: Wed, 26 Mar 2003 03:10:57 +0000
Subject: note 30697 added to function.odbc-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-45831@lists.php.net to get a copy of this message
Using your code, and taking it a step further, I can create a standard table from a single line of code by calling a function from my include file - the bonus is, that I can optionally provide a parameter for the name of my style sheet class - further simplifying my formatting of the table. What synergy you find in these forums - eh? $Conn = odbc_connect('dsn','user','pass'); $query = "SELECT * FROM yourtable"; $result = odbc_exec($Conn, $query) or die('Select failed!'); standard_table($result); Function standard_table($result,$class='') { # To format your table if you want to use cascading style sheets if ($class == '') { $css_table = ' border=1'; $css_tr = ''; $css_th = ''; $css_td = ''; } else { $css_table = ' class=\"$class\"'; $css_tr = ' class=\"$class\"'; $css_th = ' class=\"$class\"'; $css_td = ' class=\"$class\"'; } # Create field names for table header row $i = 0; $fCount = odbc_num_fields($result); echo "<table$css_table><tr>"; while ($i < $fCount) { $i++; $fName = odbc_field_name($result, $i); echo "<th>$fName</th>"; } echo "</tr>"; # Create table data rows for query result $i = 0; $fCount = odbc_num_fields($result); while (odbc_fetch_row($result)) { echo "<tr>"; while ($i < $fCount) { $i++; $fName = odbc_field_name($result, $i); $job[$fName] = odbc_result($result, $i); echo "<td>$job[$fName]</td>"; } echo "</tr>"; $i = 0; } echo "</table>"; } -- http://www.php.net/manual/en/function.odbc-field-name.php http://master.php.net/manage/user-notes.php?action=edit+30697 http://master.php.net/manage/user-notes.php?action=delete+30697 http://master.php.net/manage/user-notes.php?action=reject+30697

« previous php.notes (#45831) next »