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

php循环问题?

WBOY
WBOYOriginal
2016-06-23 14:24:161070browse

$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";
}

Statement:
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
Previous article:问个SQL查询语句Next article:SQL语句求指导