Home > Backend Development > PHP Tutorial > php循环问题?

php循环问题?

WBOY
Release: 2016-06-23 14:24:16
Original
1065 people have browsed it

$writefile=" $query = $db->query("SELECT aid,softurl FROM {$pre}article_content_106");
while($rs = $db->fetch_array($query)){
$writefile.="$rs[sorturl]\r\n";
}
write_file(ROOT_PATH."data/url_txt.php",$writefile);




怎么让这个循环在读取数据,到了100条的时候 ,换两行空行,与下面的100条有分隔的作用??


回复讨论(解决方案)

计数,i=1开始,每次加1, i % 100 = 0后输出 

$n = 1;
while($rs = $db->fetch_array($query)){
  $writefile.="$rs[sorturl]\r\n";
   $writefile .= ($n++%100)? '' : "\r\n\r\n";
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template