A while loop in PHP PHPcodewhile ($ rowsmysql_fetch_array (mysql_query (& quot; selectpl_titlefrompagelinkslimit1, 2 & quot;) {$ string $ rows [pl_title]; $ string1urlencode ($ stri a while loop in PHP
PHP code
while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,2"))){ $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]; //echo $match[1][0]; }
In this way, the processing of two data records will time out more than 30 seconds. is the statement incorrect? The purpose is to process data in batches. if is used to process one piece of data, there is no problem.
------ Solution --------------------
While ($ rows = mysql_fetch_array (mysql_query ("select pl_title from pagelinks limit 1, 2 ")))
Think about whether the value of this expression will change to false. every cycle will execute mysql_query ("select pl_title from pagelinks limit 1, 2"), then the result you get will always be the first one and fall into an endless loop.
------ Solution --------------------
If you separate mysql_query (), it will not time out. Your writing is in an endless loop.
------ Solution --------------------
While ($ rows = mysql_fetch_array (mysql_query ("select pl_title from pagelinks limit 1, 2") is executed for each loop ")))
I think it is separate writing.
$ SQL = "select pl_title from pagelinks limit 1, 2 ";
$ Rs = mysql_query ($ SQL );
.....
And while {} should start from start to end, 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];
//
}
Otherwise, it will be an endless loop.
------ Solution --------------------
You still have to retrieve mysql_query ().
------ Solution --------------------
$ 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 );
------ Solution --------------------
Discussion
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;
......
------ Solution --------------------
Executing SQL statements in a loop is a very inefficient method. you are advised to change it to another method!
------ Solution --------------------
PHP code