$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
//How to echo column names and values here?
}
Is it possible to echo a table's column names and values while iterating through the entire table in a while
loop?
You can use foreach loop
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
print "$key = $value <br />";
}
}
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
print_r($row);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With