而($ query6 = mysql_fetch_array (query5美元)).它会运行多少次?如果是从数据库中选


while($query6=mysql_fetch_array($query5)).How many times it will run?If it select 4 values from the database

我在php中应用while循环,但它运行4次,因为它从数据库中选择4个值。但是我想根据我定义的if else条件运行while循环。

<td style="border:1px solid;padding:11px;">
<?php   
    $query5=mysql_query("select atime from doctorbooking where aday='2016-09-29' and demail='".$query2['email']."'");
    while( $query6=mysql_fetch_array($query5)) {           
        if (($array_of_time[$key] . ' - ' . $array_of_time[$key+1])==$query6['atime']) {
            echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;background-color:#C0C0C0;">Booked</span>';
        } else {
            echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;">Available</span>';
        }           
    }    
?>
</td>

按照您的逻辑,您的array_of_time只能可用已预订。所以你需要打开一个旗子,然后检查它。我不知道你是想显示available还是 booking ,所以下面的例子将强制显示 booking :

<td style="border:1px solid;padding:11px;">
<?php
  $array_filter = $array_of_time[$key] . ' - ' . $array_of_time[$key+1];
  $is_booked = false; //set it true if you want to force "available"
  $query5=mysql_query("select atime from doctorbooking where aday='2016-09-29' and demail='".$query2['email']."'");
  while( $query6 = mysql_fetch_array($query5) ) {           
    if ( $array_filter == $query6['atime'] ) {
      //it force "booked" as soon as 1 is booked
      $is_booked = true;
    } else {
     // OR uncomment here to force "available" as soon as 1 is availabe
     //$is_booked = false;
    }           
  }
  if ($is_booked) {
    echo $array_filter . '<br /><span style="color:red;background-color:#C0C0C0;">Booked</span>';
  } else {
    echo $array_filter . '<br /><span style="color:red;">Available</span>';
  }
?>
</td>