PHP中的一个while循环
PHP code1
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http:
Salin selepas log masuk
这样处理2条数据,都会超过30秒超时,是语句错了吗?目的是批量处理数据,用if处理一条一条的数据,就没有问题。
------解决方案-------------------- while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,2")))
想想看这个表达式的值会否变成false,每次循环都会执行mysql_query("select pl_title from pagelinks limit 1,2"),那么你获得的结果就永远只是第一条,陷入死循环
------解决方案-------------------- 你把mysql_query()分离出来应该不会超时。你那样写陷入死循环了。
------解决方案-------------------- 每次循环都会执行while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,2")))
觉得就是分开写吧
$sql="select pl_title from pagelinks limit 1,2";
$rs=mysql_query($sql);
.....
而且while{}应该从头到尾吧,while(..){
$string=$rows['pl_title'];
$string1=urlencode($string);
echo $string;
$url = "http://localhost/index.php/"."$string1";
$contents = file_get_contents($url);
if((preg_match_all('/(
)/iUs', $contents, $match))){ $contents = $match[1][0]; } else{ (preg_match_all('/()/iUs',$contents,$match)); $contents = $match[1][0]; // } 不然在while里面出不来了,就是死循环了------解决方案-------------------- 还是得把mysql_query()拿出来------解决方案-------------------- $query = mysql_query("select pl_title from pagelinks limit 1,3"); while ($rows=mysql_fetch_array($query)){ $string[]=$rows['pl_title']; $string1=urlencode($string); } print_r($string);------解决方案--------------------
探讨
PHP code $query = mysql_query("select pl_title from pagelinks limit 1,3"); while ($rows=mysql_fetch_array($query)){ $string=$rows['pl_title']; $string1=urlencode($string); } echo $string; ……
------解决方案-------------------- 循环里面执行sql语句可是个效率很低的方法,建议换个别的方法!------解决方案-------------------- PHP code1
2
3
4
5
6
<?php
$DBserver
=
"localhost"
;
$DBname
=
"wikidb"
;
$DBuser
=
"root"
;
$DBpassword
=
""
;
</div></h1.>
Salin selepas log masuk