$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?
是否可以在while循环中迭代整个表时回显表的列名和值?
3 个解决方案
#1
13
You can use foreach loop
你可以使用foreach循环
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
print "$key = $value <br />";
}
}
#2
1
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
print_r($row);
}
#3
-2
try this.. column_name is the same name u used in the table
试试这个.. column_name与你在表中使用的名称相同
echo $row['column_name'];
#1
13
You can use foreach loop
你可以使用foreach循环
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
foreach($row as $key => $value) {
print "$key = $value <br />";
}
}
#2
1
$query = mysql_query("SELECT * FROM mytable");
while ($row = mysql_fetch_assoc($query)) {
print_r($row);
}
#3
-2
try this.. column_name is the same name u used in the table
试试这个.. column_name与你在表中使用的名称相同
echo $row['column_name'];