doubei8168 2013-09-09 15:49
浏览 107
已采纳

在PHP while循环期间页面不会加载和服务器崩溃

I am trying to run a php script that says basically, whilst two cells in my MySQL database are empty (t_trailerarrival and t_endsort), do something.

My code is as follows:

<?php
// Start Session, include authentication and dBConnection script
session_start();
include 'dbcon.php';
include 'sql_actuals.php';
$current_time = date("G"); 

while($query9_row['a_trailerarrival'] == NULL && $query10_row['a_endsort'] == NULL) {
    echo "Trailer Arrival";
}

The $queryx_row['abc'] are all in the sql_actuals script that is included into this script.

For some reason, every time i run this script - my browser wont load the result (just loads for ever) and then my website at windows azure seems to crash and take a few minutes to restart.

Could someone please advise if there is a massively obvious error with my script? or point me at what the possible issue could be.

Many thanks in advance.

FYI, i have tried adding a line sleep(1); so that it gave the server it runs off a delay before having to run the program again but no luck.

  • 写回答

2条回答 默认 最新

  • doume1301 2013-09-09 15:51
    关注

    You are not actually doing anything in your while statement except echoing a line.

    Therefore

    $query9_row['a_trailerarrival'] == NULL 
    

    and

    $query10_row['a_endsort'] == NULL
    

    are always true and never changing, and it will never exit the while loop. You need to put exit criteria in the while loop, such as:

    $i=0;
    while(($query9_row['a_trailerarrival'] == NULL 
            && $query10_row['a_endsort'] == NULL ) 
           || $i==10) {
        $i++;
        echo "Trailer Arrival";
    }
    

    Although, logically speaking, you still need to run the query data.

    ** Edit ** Based upon your feedback, this doesn't sound like a while loop at all, but rather an if statement you need (with multiple elseif s).

    if ($query9_row['a_trailerarrival'] == NULL && $query10_row['a_endsort'] == NULL){
       echo "Trailer Arrival";
    } elseif ($query9_row['a_trailerarrival'] == NULL  && $query10_row['a_endsort']){
       echo "End Sort";
    } elseif ($query9_row['a_trailerarrival']  && $query10_row['a_endsort']){
       echo "First Van";
    }else {
      // fourth condition:
      // $query9_row['a_trailerarrival'] != NULL &&  $query10_row['a_endsort'] == NULL
    }
    

    I included a fourth condition when $query9_row isn't null, and $query10_row is null.

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

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。