日期:2014-05-17  浏览次数:20463 次

新手提个问:怎么把php的变量赋值到html里
我绝对是菜鸟,0起点,来帮帮我吧,自己用的。
<div align="left">
  <h1 align="center">&nbsp;</h1>
  <h1 align="center"><strong>这里放个变量$data</strong></h1>
  <p align="center">&nbsp;</p>
</div>
<?php
...这里连接数据库
$data=xxx
?>


怎么把后面数据库的结果给他赋过去。

------解决方案--------------------

<?php
...这里连接数据库
$data=xxx
?>
<div align="left">
  <h1 align="center">&nbsp;</h1>
  <h1 align="center"><strong><?php var_dump($data)?></strong></h1>
  <p align="center">&nbsp;</p>
</div>

还是用个smarty什么的吧 程序和模版分开写好一点
------解决方案--------------------

<?php
...这里连接数据库
$result = mysql_query($sql);
?>
<div align="left">
  <h1 align="center">&nbsp;</h1>
<?php
   while($data = mysql_fetch_assoc($res)){
?>
  <h1 align="center"><strong>这里放个变量<?php echo $data['xxx']?></strong></h1>
<?php
}
?>
  <p align="center">&nbsp;</p>
</div>


大概格式是这样的