search

Home  >  Q&A  >  body text

Help from a newbie: About the loop that generates static lists in PHP

Let me ask you guys, PHP generates a static list. After the loop, the database value is normal, but the generated html data keeps repeating the data of the first loop.

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); 	
}


°无恙。°无恙。2070 days ago1070

reply all(1)I'll reply

  • 殘留の回憶

    殘留の回憶2019-05-25 09:33:53

    You have been traversing the database in the for loop, and of course the data that comes out is repeated. Just put the while loop of the database outside and i inside it

    reply
    0
  • Cancelreply