2016-05-22 74 views
-1

我试图循环访问我的数据库,并在满足某些过滤条件(包括检查标头数据以查看url是否存在)之后向数组中添加数据。PHP while while循环gettng卡住

我看到,循环执行第一轮,因为我看到回声结果,如果我打破循环与退出。但如果我不这样做,它不会回应任何事情,并会无限无尽地做任何事情!

代码:

$gp=0; 
include('connnew.php'); 
$getpages=$clientdb->query("SELECT * FROM clientdata ORDER BY Date DESC") or die("Pages Error : ".$clientdb->error); 
while($subdinf=$getpages->fetch_assoc()){ 
$gp++; 
echo "<div style='position:absolute;top:150px;right:60px;'>$gp</div>"; 
$subdinf['propheading']=$subdinf['propheading']."-".$subdinf['Id']; 
$proph=$subdinf['propheading']; 
$page=trim(str_replace($splchrs,'-',$proph)); 
$page=trim(str_replace("&","and",$page)); 
$page=trim(str_replace(array("---","--"),'-',$page)); 

if(substr($page,0,32)!="Want-to-Buy-any-kind-of-property" && substr($page,0,40)!="For-sale-1-BHK-2BHK-and-other-properties" && substr($page,0,38)!="Wanted-Apartments-and-other-properties"){ 
$html5="http://www.landshoppe.com/$page"; 

$file_headers = get_headers($html5); 

      if($file_headers[0] == 'HTTP/1.1 404 Not Found') { 
       $exists = false; 
       echo "<h3>URL ".$html5." Does not exist !</h3>"; 
       } 
       else { 

       $exists = true; 
        if(!in_array($html5,$link)){ 
         $link[]=$html5; 
        echo $html5."<br>"; 

         } 
        } 
      } 
//echo $gp;exit; 
} 
echo "Total Pages : $gp<br><br>";exit; 

有人可以帮助我了解,而我对一些输出无限期地等待发生了什么?

+0

使用'@'进行错误抑制会隐藏任何有用的消息。先删除那个,然后回来看看你看到的任何错误消息。 – vascowhite

+0

“做一个无意的监督优点快速投票”,是的,因为它与诊断问题非常相关,这也是非常糟糕的做法,我每次看到它都会失望。 – vascowhite

回答

1
$getpages->fetch_assoc() 

会给你一个需要在foreach循环内运行的数组。那$ gp在做什么?它只是在无限的时间循环中递增。你可以做的是

while($subd=$getpages->fetch_assoc()){ 

foreach ($subd as $subdinf){ 
    //put rest of the code inside this 
} } 

这确保了当数组计数结束时,它会停止循环。

您可以使用输出缓冲来显示循环的状态

ob_start(); 
// Your entire function here 
$output = ob_get_clean(); 

echo $output; 

检查此链接和下面给出的例子。你会明白 http://php.net/manual/en/ref.outcontrol.php

+0

谢谢阿米特的建议。脚本以某种方式开始工作......本身!猜猜我必须等待足够长的时间!唯一的事情是,如果在等待完成的过程中有一些方法可以知道进程的状态,那本来是很好的! – user3526204