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('/(<h1.*<\/table>)/iUs', $contents, $match))){
$contents = $match[1][0];
}
else{
(preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
$contents = $match[1][0];
//echo $match[1][0];
}这样处理2条数据,都会超过30秒超时,是语句错了吗?目的是批量处理数据,用if处理一条一条的数据,就没有问题。

解决方案 »

  1.   

    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"),那么你获得的结果就永远只是第一条,陷入死循环
      

  2.   

    因为怕超时,所以想批量处理数据:
    select pl_title from pagelinks limit 1,100
    select pl_title from pagelinks limit 101,100
    select pl_title from pagelinks limit 201,100
    ...
      

  3.   

    你把mysql_query()分离出来应该不会超时。你那样写陷入死循环了。
      

  4.   


    嗯,用while就是永远陷入死循环
    while($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 1,1")))
    这样也会超时,打印了看就是永远第一条。while(($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 14,2")))!=false){
    $string=$rows['pl_title'];
    $string1=urlencode($string);
    }
    echo $string;$url = "http://localhost/index.php/"."$string1";
    $contents = file_get_contents($url);if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
    (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
    $contents = $match[1][0];
    //echo $match[1][0];
    }
    现在代码这样还是死循环,但是把while改成if,每一条数据都可以成功。
    用while就不行了
      

  5.   

    每次循环都会执行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('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
        (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
        $contents = $match[1][0];
        //
    }
    不然在while里面出不来了,就是死循环了
      

  6.   

    都说了那个表达式永远也不会是false,走正常的道就给解决了
    mysql_query("select pl_title from pagelinks limit 14,2"))
    while( $rows=mysql_fetch_array($query) ){
        $string=$rows['pl_title'];
        $string1=urlencode($string);
    }
      

  7.   

    $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;这样可以编译,但是只运行最后一条的数据呀,1到4条,就只有第4条的结果。
      

  8.   


    $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);
      

  9.   


    Warning: urlencode() expects parameter 1 to be string, array given in :$string1=urlencode($string);
      

  10.   


    是while的范围大小了,要扩大~~
      

  11.   

    循环里面执行sql语句可是个效率很低的方法,建议换个别的方法!
      

  12.   

    不知道你想要哪种结果。要原数据还是urlencode之后的? 
    $query = mysql_query("select pl_title from pagelinks limit 1,3");
    while ($rows=mysql_fetch_array($query)){
    $string[]=$rows['pl_title'];
    $string1[]=urlencode($rows['pl_title']);
    }
    print_r($string);
    print_r($string1);
      

  13.   

    要2个结果:一个是要存$string,另一个是要转urlencode()
      

  14.   

    楼主还没改过来?你把mysql_query()放在循环里面意味着while每次都会去执行数据库查询,而且总是会有结果,那你的mysql_fetch_array() 就总是不会取到空的值,那你的$rows 就不会是false,导致你的while会死循环。简单点的你就照楼上同志修改吧。
      

  15.   

    我把现在的代码贴出来吧:
    <?php
    $DBserver         = "localhost";
    $DBname           = "wikidb";
    $DBuser           = "root";
    $DBpassword       = "";
    mysql_connect("localhost","root","");
    mysql_select_db("wikidb");//if($rows=mysql_fetch_array(mysql_query("select pl_title from pagelinks limit 14,1"))){
    $query = mysql_query("select pl_title from pagelinks limit 1,3");
    while ($rows=mysql_fetch_array($query)){
    $string[]=$rows['pl_title'];
    $string1[]=urlencode($rows['pl_title']);
    }
    print_r($string);$url = "http://localhost/index.php/"."$string1";
    $contents = file_get_contents($url);if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
    $contents = $match[1][0];
    }
    else{
    (preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match));
    $contents = $match[1][0];
    }

    $DBserver         = "localhost";
    $DBname           = "new";
    $DBuser           = "root";
    $DBpassword       = "";
    mysql_connect("localhost","root","");
    mysql_select_db("new");
    mysql_query("set names 'utf8'");
    $sql="";
    mysql_query($sql);
    $SQL="INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$contents}')";
    mysql_query($SQL);
    ?>要批量处理,然后下面还要根据转的url,链接到页面,截取页面信息!再把$string和$contents存如数据库。
      

  16.   

    <?php
    $DBserver         = "localhost";
    $DBname           = "wikidb";
    $DBuser           = "root";
    $DBpassword       = "";
    // mysql 连接,下面代码都将使用这个
    $con = mysql_connect("localhost","root","");mysql_select_db("wikidb");
    $query = mysql_query("select pl_title from pagelinks limit 1,3") or die(mysql_error() );// 更换数据库
    mysql_select_db("new", $con);while ($rows=mysql_fetch_array($query))
     {
        $string   =$rows['pl_title'];
        $string1  =urlencode($rows['pl_title']);
        // 下面仍是循环的一部分    $url = "http://localhost/index.php/"."$string1";
        $contents = file_get_contents($url);    if((preg_match_all('/(<h1.*<\/table>)/iUs', $contents, $match))){
             $contents = $match[1][0];
        }
        else{
             preg_match_all('/(<h1.*<\/ol>)/iUs',$contents,$match);
             $contents = $match[1][0];
        }
        
        // 连接的代码被删除了,你只需要改变连接到的数据库在while上一行
        
        mysql_query("set names 'utf8'");
        // 下面两句是什么意思?
        // $sql="";
        // mysql_query($sql);    $SQL="
      INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$contents}')";
        // 查询,失败返回错误消息
        mysql_query($SQL) or die(mysql_error());}
    // while循环结束
    ?>