Hi,
I want to query an db, show the results with the field names on top.
I can get the fieldnames but if i limit the select statement to two fields for instance it will keep displaying all the field names of the table.
this is what i have, i only include the result
<code>
echo "<table>\n";
echo "<tr>\n";
$fields = mysql_listfields( "database", "table");
$field_num = mysql_num_fields($fields);
$i=0;
while ($i < $field_num){
$col_name = mysql_field_name ($fields, $i);
echo "<td>$col_name</td>";
$i++;
}
echo "</tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
</code>
Can anyone help me with this ? I googled around for a long time but could not get an good tutorial about this.
Thanks.
Alex