A while loop solution in PHP

Source: Internet
Author: User
A while loop in PHP
PHP Code
  
   while ($rows =mysql_fetch_array (mysql_query ("Select Pl_title from Pagelinks limit")) {    $string = $rows [' Pl_ Title '];    $string 1=urlencode ($string);} echo $string; $url = "http://localhost/index.php/". " $string 1 "; $contents = file_get_contents ($url); if (Preg_match_all ('/(
  <><\ table="">
   )/ius ', $contents, $ Match)) {$contents = $match [1][0];} else{    (Preg_match_all ('/(
   <><\ ol="">
   
    )/ius ', $contents, $match));    $contents = $match [1][0];    Echo $match [1][0];    }
   <\>
  <\>
   
   
   


This process 2 data, will be more than 30 seconds timeout, is the statement wrong? The goal is to process the data in batches, with if processing a single piece of data, there is no problem.


------Solution--------------------
while ($rows =mysql_fetch_array (mysql_query ("Select Pl_title from Pagelinks limit"))
Think about whether the value of this expression will become false, and each loop will execute mysql_query ("Select Pl_title from Pagelinks limit"), then you will always get the first result, and you'll be in a dead loop.
------Solution--------------------
You should not time out if you separate the mysql_query (). You write like that into a dead loop.
------Solution--------------------
The while ($rows =mysql_fetch_array (mysql_query ("Select Pl_title from Pagelinks limit") is executed for Each loop
I think it's just a separate writing.
$sql = "Select Pl_title from Pagelinks limit";
$rs =mysql_query ($sql);
.....
and while{} should be from beginning to end, while (..) {
$string = $rows [' Pl_title '];
$string 1=urlencode ($string);

Echo $string;

$url = "http://localhost/index.php/". " $string 1 ";
$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's not going to come out of the while, it's a dead loop.
------Solution--------------------
Still have to take mysql_query () out
------Solution--------------------

$query = mysql_query ("Select Pl_title from Pagelinks limit 1,3");
while ($rows =mysql_fetch_array ($query)) {
$string []= $rows [' Pl_title '];
$string 1=urlencode ($string);
}
Print_r ($string);
------Solution--------------------
discuss
PHP Code


$query = mysql_query ("Select Pl_title from Pagelinks limit 1,3");
while ($rows =mysql_fetch_array ($query)) {
$string = $rows [' Pl_title '];
$string 1=urlencode ($string);
}
Echo $string;

......

------Solution--------------------
Loop inside the execution of SQL statements is a very inefficient method, suggest a different way!
------Solution--------------------
PHP Code
    ) (/ius ', $contents, $match))) {$contents = $match [1][0]; } else{Preg_match_all ('/(
    
     
      )/ius ', $contents, $match);    $contents = $match [1][0];    }//The connected code is deleted, you only need to change the connection to the database in the while on the line mysql_query ("Set names ' UTF8 ');    What do the following two sentences mean?    $sql = "";    mysql_query ($sql);    $SQL = "INSERT into pagecontents (old_title,old_text) VALUES (' {$string} ', ' {$contents} ')"; Query, Failure returns error message mysql_query ($SQL) or Die (Mysql_error ());} While loop ends?> 
      
  • 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.