?>php
while ($row = mysql_fetch_object($sql)) {
echo $row->%;
}
?>
//error Parse error: syntax error, unexpected '%', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$
答案 0 :(得分:1)
<?php
while ($row = mysql_fetch_assoc($sql)) {
echo $row['%'];
}
?>
答案 1 :(得分:1)
$sql = "SELECT 'A' AS `%`";
$res = mysql_query($sql);
$row = mysql_fetch_object($res);
$colName = '%';
echo $row->$colName;
注意:
mysql
函数,因为它们已被弃用。请改用mysqli
或PDO
。答案 2 :(得分:1)
您需要使用{}
:
echo $row->{'%'};