php, mysql, how can I get the field name inside my dynamic sql html table loop?

watkinspig

New Member
I'd like to do something different depending on field name in my loop. My code dynamically produces a html table based on the fields used in the sql query. I'd like to produce a link to a certain page if the field in the loop is the primary key... Any ideas ? I've marked where I need to get the field name with HERE.\[code\] if (mysql_num_rows($result)>0) { //loop thru the field names to print the correct headers $i = 0; while ($i < mysql_num_fields($result)) { $out .= "<th bgcolor='#CFCFCF'><font size=2>". mysql_field_name($result, $i) . "</font></th>"; $i++; } echo "</tr>"; //display the data while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)) { $out .= "<tr>"; foreach ($rows as $data) { //HERE $out .= "<td bgcolor='#DCDCDC'><font size=2>". $data . "</font></td>"; } } }\[/code\]
 
Back
Top