Home > php教程 > php手册 > php while循环得到循环次数

php while循环得到循环次数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:27:07
Original
1288 people have browsed it

在for循环中,我们很容易得到循环次数,因为是作为条件出现的。在while也可以得到,如下:

复制代码 代码如下:


   $link = mysql_connect('localhost','root','pwd');
   mysql_select_db('db'); 
   $sql = "select region_id,local_name from regions where region_grade=1";
   $result = mysql_query($sql);
 $i =0;
  while ($row= mysql_fetch_assoc($result)) {
        $list[$i]['text']=$row['local_name']; 
        $list[$i]['value']=$row['region_id'];
        $i++;      
   }
  $list = json_encode($list);
  echo   $list;
?>


在实际工作,偶尔会用到的。 ,
Related labels:
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
Latest Issues
while loop
From 1970-01-01 08:00:00
0
0
0
An error occurred while accessing the login page
From 1970-01-01 08:00:00
0
0
0
java - Questions about While,break
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template