2015-10-06 129 views
-7

我在打印PHP标签中已经回显的html标签中的变量时遇到麻烦?我想在h1标签中打印$变量。我的代码:在已经在php标签中回显的html标签中打印php变量

<?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

这是什么问题?你有任何错误?你得到了什么,你期望什么? – Rizier123

+2

这应该已经工作:) https://eval.in/445359 –

+0

这是没有标题和旧金山,加利福尼亚州。那是你所期望的吗? – jessica

回答

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>没有正确的代码关闭。

+0

无论是否有封闭的html标签,它都会输出相同的东西。 – jessica

+1

哇@jessica,你就像幸运的卢克。减去1比你的影子快。 – Vico

+2

而且你认为最糟糕的人比你的影子快。我只对你的帖子发表了评论。 – jessica

-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>" 
?> 
+0

什么是解决方案?问题本身是模糊的,这怎么可能被引用为答案? –

+0

@HongNV选项1和2都没有任何返回。如果我在选项2中使用单引号就像这样>>'。$ A'。那么它只是返回'..' –