我无法在html标签中打印一个已经在php标签中回显的变量?我想在h1标签中打印$ A变量。我的代码:
<?php
while($pr = mysql_fetch_assoc($qAccess))
{
$id=$pr["user_id"];
$A=$pr["name"];
}
echo "<html
<!-- Profile info -->
<div id='profile_info'>
<h1 id='name' class='transition-02'>$A</h1>
<h4 class='line'>no heading</h4>
<h6><span class='fa fa-map-marker'></span> San Francisco , CA</h6>
</div>
<!-- End Profile info -->
</html>" ;
?>
答案 0 :(得分:0)
我认为你应该把回声放在while循环中。 如果你不这样做,它只会显示你阵列的最后一次出现。
试试这个:
<?php
echo "<html>";
while($pr = mysql_fetch_assoc($qAccess)) {
$id = $pr["user_id"];
$A = $pr["name"];
echo "<!-- Profile info -->
<div id='profile_info'>
<h1 id='name' class='transition-02'>$A</h1>
<h4 class='line'>no heading</h4>
<h6><span class='fa fa-map-marker'></span> San Francisco , CA</h6>
</div>
<!-- End Profile info -->";
}
echo "</html>" ;
?>
否则可能是因为代码中没有正确关闭<html>
。
答案 1 :(得分:-2)
2个选项
- 选项1:
<div id='profile_info'>
<h1 id='name' class='transition-02'><?=$a?></h1>
<h4 class='line'>no heading</h4>
<h6><span class='fa fa-map-marker'></span> San Francisco , CA</h6>
</div>
- 选项2:
<?php
echo "<html>
<!-- Profile info -->
<div id='profile_info'>
<h1 id='name' class='transition-02'>".$A."</h1>
<h4 class='line'>no heading</h4>
<h6><span class='fa fa-map-marker'></span> San Francisco , CA</h6>
</div>
<!-- End Profile info -->
</html>"
?>