I would like to print a list with all field names and their values from a table in a mysql database. How would i use a loop to print:
FIELD NAME
Solution 1:
This is very basic PHP, a simple while-loop combined with a foreach would suffice:
echo'<table>';
$query = mysql_query("SELECT * FROM `your_table`");
// Loop over all result rowswhile($row = mysql_fetch_assoc($query)) {
// Loop over all fields per rowforeach($rowas$field => $value) {
echo'<tr><td>' . htmlentities($field) . '</td><td>' . htmlentities($value) . '</td></tr>';
}
// New data row can optionally be seperated with a blank line hereecho'<tr><td colspan="2"> </td></tr>';
}
echo'</table>';
Solution 2:
Use mysql_field_name(), mysql_num_fields(), mysql_fetch_field(), mysql_field_seek().
Post a Comment for "Echo Out All Field Names Along With Their Respective Values"