php循环生成html

这时候我写的生成html的代码,只能循环一次,不知道该怎么改?<?php$con=mysql_connect("localhost","root","");if(!$co... 这时候我写的生成html的代码,只能循环一次,不知道该怎么改?

<?php

$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("getjson",$con);
$sql = "SELECT * from user";
$result = mysql_query($sql,$con);
$data = mysql_fetch_array($result);
$tiaoshu = count($data);

$tpl = 'index.tpl';

for ($i = 0; $i < $tiaoshu; $i++) {

$content = file_get_contents($tpl); //读取模板文件的内容
$content = str_replace('{title}',$data['username'],$content); //用具体数据来替换模板标签
file_put_contents($data['id'].'.html',$content); //将替换后的内容写进html文件中
}
?>
展开
 我来答
百krfh
2013-10-17 · TA获得超过160个赞
知道小有建树答主
回答量:199
采纳率:0%
帮助的人:169万
展开全部
你只是读了一条,循环怎么能出现多次呢
for 循环换一下
while($data = mysql_fetch_array($result))
{

$content = file_get_contents($tpl); //读取模板文件的内容
$content = str_replace('{title}',$data['username'],$content); //用具体数据来替换模板标签
file_put_contents($data['id'].'.html',$content); //将替换后的内容写进html文件中
}
564643122abc
2013-10-17 · TA获得超过462个赞
知道小有建树答主
回答量:699
采纳率:0%
帮助的人:395万
展开全部
echo $tiaoshu 看看是多少

我觉得应该用

$tiaoshu = mysql_num_rows($result);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式