$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
//How to echo column names and values here?
}
是否可以在while
循环中遍历整个表时回显表的列名和值?
答案 0 :(得分:14)
您可以使用foreach循环
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
print "$key = $value <br />";
}
}
答案 1 :(得分:1)
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
print_r($row);
}
答案 2 :(得分:-2)
试试这个.. column_name与表中使用的名称相同
echo $row['column_name'];