请教下各位大佬,php生成静态列表,循环之后数据库值是正常的,但是生成的html数据一直重复第一次循环的数据。
for ($i=0; $i < $allpages; $i++){
if ($i==0)
{
$indexpath = "index_0.html";
}
else
{
$indexpath = "index_".$i.".html";
}
$star = $i* $onepage;
$list ='';
$sql= "select path,title from article limit $star,$onepage";
$result = mysql_query ($sql);
while($row=mysql_fetch_assoc($result))
{
$list.= '<a href="2019/'.$row['path'].'" target="_blank"><li>'.$row['title'].'</li></a><br>';
}
$content = str_replace("{articletable}",$list,$content);
if (is_file ($indexpath))
{
@unlink ($indexpath);
}
$handle = fopen ($indexpath,"w");
fwrite ($handle,$content);
fclose ($handle);
}Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你在for循环里一直在遍历数据库,出来的当然都重复的数据,把数据库的while循环放外面,i放里面就可以了