A while loop solution in PHP-php Tutorial

Source: Internet
Author: User
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
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.