2011-03-29 110 views
0

我有一个小的PHP函数从我的一个页面调用。PHP函数givine IE问题

function ratingDetails($uid, $align, $width) { 
$queryFull = "SELECT * FROM rating WHERE uid = $uid"; 
$resultFull = mysql_query($queryFull); 

     //START DISPLAY TABLE IF RESULTS 
     if(mysql_num_rows($resultFull) > 0) {  

      echo "<table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" width=\"550\">\n"; 
      echo "<tr bgcolor=\"#6699cc\"><th>STARS</th><th>DATE RATED</th><th>COMMENT</th><th>RATED BY</th></tr>\n"; 

       while($rowFull = mysql_fetch_array($resultFull)) { 
        $rating = $rowFull['rating']; 
        $comment = $rowFull['comment']; 
        $datePosted = date("M j, Y", $rowFull['date']); 
        $rid = $rowFull['raterID']; 
        $rater = getUsername($rid); 

        //SHOW STARS 
        if($rating == 0) { $stars = "notYet.jpg"; } 
        if($rating == 1) { $stars = "starOne.jpg"; } 
        if($rating == 1.5) { $stars = "starOneHalf.jpg"; } 
        if($rating == 2) { $stars = "starTwo.jpg"; } 
        if($rating == 2.5) { $stars = "starTwoHalf.jpg"; } 
        if($rating == 3) { $stars = "starThree.jpg"; } 
        if($rating == 3.5) { $stars = "starThreeHalf.jpg"; } 
        if($rating == 4) { $stars = "starFour.jpg"; } 
        if($rating == 4.5) { $stars = "starFourHalf.jpg"; } 
        if($rating == 5) { $stars = "starFive.jpg"; } 

        //DISPLAY IT ALL 
        echo "<tr><td width=\"10\"><img src=\"/images/rating/$stars\" width=\"105\" height=\"20\" /></td>"; 
        echo "<td width=\"75\" align=\"center\">$datePosted</td><td>$comment</td><td width=\"85\">$rater</td></tr>\n"; 
       }//END WHILE 
       echo "</table>\n"; 
     } //END IF 
     else { 
      echo "<table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"8\" width=\"550\">\n"; 
      echo "<tr><td align=\"center\"><span class=\"blue\">NO REVIEWS OR RATINGS FOR THIS DISTRIBUTOR</span></td></tr></table>\n";  

     }  //END IF ELSE 

}

但是,当它在IE运行(7或8),它引发此错误:

A script on this page is causing Internet Explorer to run slowly. Bla bla bla...

我请从两页此功能两者导致同样的错误。如果我从该页面中删除该呼叫,则该页面加载正常。

没有涉及问题的网页的JavaScript ...

帮助,帮助,帮助...我没有留下多少头发...

里克

+3

查询返回多少行? – 2011-03-29 15:53:01

+0

您在这些页面上加载了任何Flash(.swf)文件吗? – 2011-03-29 15:55:08

+0

我想,你使用“千兆字节”表来获取。您是否尝试使用其他浏览器(例如Firefox,Chrome,Opera,Safari)加载您的网页? – Wh1T3h4Ck5 2011-03-29 15:57:00

回答

1

发生什么事是执行脚本需要很长时间。 IE正在等待来自服务器的输出,但这需要很长时间。

您可能想要尝试调用flush()每行(或者可能每25行使用模运算符)或使用ob_implicit_flush()打开隐式刷新。这样你有数据不断回到浏览器(我假设你有大量的数据)。您可能还需要调用set_timeout(0)来禁用脚本的30秒时间限制。

+0

感谢您的协助! 但是,我还在开发中,只有15个左右的MySQL数据库记录。即便如此,我还是要看看你推荐的flush()和set_timeout()函数。 再次感谢您的帮助! – Rick 2011-03-29 16:17:53

+0

如果你只有15条记录,那么你就会挂在别的地方。 – 2011-03-29 16:22:27

0

我要做的第一件事就是摆脱所有这些星星的IF语句,或者使用它们的数组或switch语句,这两种语句都会减少脚本所需的处理。一个数组将是我的方法。您的代码如下所示:

function ratingDetails($uid, $align, $width) { 

$ queryFull =“SELECT * FROM rating WHERE uid = $ uid”; $ resultFull = mysql_query($ queryFull);

//为星星声明数组。 $ astars =阵列( 0 => “notYet.jpg”, 1 => “starOne.jpg”, 1.5 => “starOneHalf.jpg”, 2 => “starTwo.jpg”, 2.5 => “starTwoHalf.jpg”, 3 => “starThree.jpg”, 3.5 => “starThreeHalf.jpg”, 4 => “starFour.jpg”, 4.5 => “starFourHalf.jpg”, 5 => “starFive.jpg” );

//START DISPLAY TABLE IF RESULTS 
    if(mysql_num_rows($resultFull) > 0) {  

     echo "<table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" width=\"550\">\n"; 
     echo "<tr bgcolor=\"#6699cc\"><th>STARS</th><th>DATE RATED</th><th>COMMENT</th><th>RATED BY</th></tr>\n"; 

      while($rowFull = mysql_fetch_array($resultFull)) { 
       $rating = $rowFull['rating']; 
       $comment = $rowFull['comment']; 
       $datePosted = date("M j, Y", $rowFull['date']); 
       $rid = $rowFull['raterID']; 
       $rater = getUsername($rid); 
       $stars = $astars[$rating]; 

       //DISPLAY IT ALL 
       echo "<tr><td width=\"10\"><img src=\"/images/rating/$stars\" width=\"105\" height=\"20\" /></td>"; 
       echo "<td width=\"75\" align=\"center\">$datePosted</td><td>$comment</td><td width=\"85\">$rater</td></tr>\n"; 
      }//END WHILE 
      echo "</table>\n"; 
    } //END IF 
    else { 
     echo "<table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"8\" width=\"550\">\n"; 
     echo "<tr><td align=\"center\"><span class=\"blue\">NO REVIEWS OR RATINGS FOR THIS DISTRIBUTOR</span></td></tr></table>\n";  

    }  //END IF ELSE 

小数可能会导致数组中的问题;如果是这样,你可以把引号括起来;例如"1.5"=>"starOneHalf.jpg"

您可以做的另一件事是为HTML输出创建一个变量,而不是每行回显输出,然后在最后回显输出。

+0

我原来是用开关设置的,但是把它改成IF来看看是否是我的问题。一旦我找出我的问题的主要原因,可能会返回到开关......还尝试了变量$ table =“...”,然后返回前的回声。无论如何,似乎都没有效果。我很欣赏输入! – Rick 2011-03-29 20:33:41

0

我发现我的问题... 我的函数中的表被分配了一个CSS类。这个特定的css类包含一个叫PIE.htc的行为。显然,这会导致某种IE在被调用时会崩溃。我删除了PIE(令人沮丧,在IE中没有更多的圆角或阴影),我的问题解决了!

感谢大家一路上提供的帮助!