while循环得到循环次数
2013-05-26 01:04
190 查看
在for循环中,我们很容易得到循环次数,因为是作为条件出现的。在while也可以得到,如下:
<?php
$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;
?>在实际工作,偶尔会用到的。
<?php
$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;
?>在实际工作,偶尔会用到的。
相关文章推荐
- php while循环得到循环次数
- php while循环得到循环次数
- java基础--while循环实现A4纸折叠次数到珠穆朗玛峰高度
- for循环中的循环次数无法更改,可用while实现
- 限制输入的次数用到while循环
- 关于for循环和while循环中的次数问题
- 从键盘输入一组非0整数,以输入0为结束标志,求这组整数的平均值,并统计其中正数和负数的个数。(根据循环变量的初值、终值无法判断出循环次数时建议使用while或do while语句完成)。
- Smarty中得到foreach的当前循环次数
- Python while循环-猜年龄-无次数限制
- python while 循环-猜年龄-有次数限制
- PL/SQL:WHILE循环:打印2-200之间的素数
- Linux中posix线程的pthread_cond_wait函数为何使用while循环
- shell脚本编程循环之for/while/untill循环
- (转载)你好,C++(21)只要天还没黑,就一直在工地干活-4.3.1 while循环:只要…就一直…
- poj 2406 Power Strings(KMP求最大循环次数)
- python中的while循环
- Python while 循环
- 循环结构-while
- tf.while_loop()循环 实现
- 输入循环在什么情况下结束,while(cin>>word) 类型?