<?
require_once("db.php");
mysql_query("SET NAMES 'utf8'");
$result=mysql_query("SELECT* FROM mytable");
while($row =mysql_fetch_array($result))
{
$html ="<ul>";
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html ="</ul>";
}
file_put_contents("h1.html", $html);
?>
生成出来的html只有<ul>;
全部用$html,输出的只有数据库的的最后一个。<ul><li>name3</li></ul>
全部用$html. 输出的每一个结果外面都带<ul><li>,<ul><li>name1</li></ul><ul><li>name2</li></ul><ul><li>name3</li></ul>怎样使生成的$html为:
<ul>
<li>name1</li>
<li>name2</li>
<li>name3</li>
</ul>
require_once("db.php");
mysql_query("SET NAMES 'utf8'");
$result=mysql_query("SELECT* FROM mytable");
while($row =mysql_fetch_array($result))
{
$html ="<ul>";
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html ="</ul>";
}
file_put_contents("h1.html", $html);
?>
生成出来的html只有<ul>;
全部用$html,输出的只有数据库的的最后一个。<ul><li>name3</li></ul>
全部用$html. 输出的每一个结果外面都带<ul><li>,<ul><li>name1</li></ul><ul><li>name2</li></ul><ul><li>name3</li></ul>怎样使生成的$html为:
<ul>
<li>name1</li>
<li>name2</li>
<li>name3</li>
</ul>
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html .="</ul>";
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html .="</ul>";
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html .="</ul>";
<? require_once("db.php"); mysql_query("SET NAMES 'utf8'"); $result=mysql_query("SELECT* FROM mytable"); while($row =mysql_fetch_array($result)) { $html .="<ul>"; $html .="<li>{the name is[\"".$row["name"]."\"]}</li>"; $html .="</ul>"; } file_put_contents("h1.html", $html); ?>
require_once("db.php");
mysql_query("SET NAMES 'utf8'");
$result=mysql_query("SELECT* FROM mytable");
while($row =mysql_fetch_array($result))
{
$html .="<ul>";
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html .="</ul>";
}
file_put_contents("h1.html", $html);
?>
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
$html .="</ul>";
<ul><li>name1</li></ul><ul><li>name2</li></ul><ul><li>name3</li></ul>3楼,6楼的方法可以。谢谢。
正解应该是:
$html .="<ul>";
while($row =mysql_fetch_array($result))
{
$html .="<li>{the name is[\"".$row["name"]."\"]}</li>";
}
$html .="</ul>";
还是要谢谢大家。
PS:早上服务器发生故障,同一帖子我发了2遍,斑竹可否删掉一个, 然后把分数还给我?