duanqiao1926 2010-10-18 17:44
浏览 65
已采纳

PHP MySQL脚本出错了

I'm working on a site and created this experimental script which populates a category menu dynamically based on the database entry.

It worked for a day and then suddenly stopped. I changed my includes for requires and it gave me this error message

Fatal error: Maximum execution time of 30 seconds exceeded in /home1/advertbo/public_html/dev_area/origocloud/include/views/blog/dbget.php on line 34

function getBlogMenu(){
$dbhost = 'localhost';
$dbuser = ' ';
$dbpass = ' ';

$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ado_ocblog", $con);

$htmlString = "";

$result = mysql_query(
    "SELECT *
    FROM subCat
    JOIN headCat ON subCat.headid = headCat.id
    ORDER BY headid ASC;");

$array = mysql_fetch_array($result);
mysql_close($con);

$pre = NULL;
$hc = 0;
$sc = 1;
while ($array) {
    if($pre == NULL){
        $pre = $row["headc"];
        $test[0][0]=$row["headc"];
        $test[0][1]=$row["subc"];

    }
    else
    {
        if($pre ==$row["headc"]){
            $sc++;
            $test[$hc][$sc] = $row["subc"];

        }
        else
        {
            $hc++;
            $sc = 1;
            $test[$hc][0]=$row["headc"];
            $test[$hc][$sc]=$row["subc"];
            $pre = $row["headc"];
        }
    }

}

foreach( $test as $arrays=>$cat)
{
        $first = TRUE;
        foreach($cat as $element)
        {
            if($first == TRUE)
            {
                $htmlString.= '<h3><a href="">'.$element.'</a></h3>
                        <div>
                            <ul>
                    ';
                $first = FALSE;
            }
            else
            {
                $htmlString.= '<li><a class="sub_menu" href="#">'.$element.'</a></li>';
            }

        }
        $htmlString.= '</ul> </div>';
}
return $htmlString;


}

I'm really stuck, the page just keeps timing out the point where i call the function

  • 写回答

2条回答 默认 最新

  • dpylt7626401 2010-10-18 19:07
    关注

    Try this:

    while ($array = mysql_fetch_array($result)) {}
    

    Take a look on PHP docs http://php.net/mysql_fetch_array

    If does not work, your SQL Query returns too much values and craches the php execution

    =]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?