$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
//How to echo column names and values here?
}
是否可以在循环遍历整个表时回显表的列名和值while
?
您可以使用 foreach 循环
$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);
}
试试这个.. column_name 与您在表中使用的名称相同
echo $row['column_name'];