0

我有以下查询。如果成人人数少于 10,我想显示时间。

$result = mysql_query("SELECT sum(Adult) AS Number1, Time FROM orders WHERE confirmed = 'Y' and BookDate = '2013-04-01' GROUP BY Time");

while($row = mysql_fetch_array($result)) {

if ($row['Number1'] < '10')
echo '<div class="result">'.$row['Time'].' ('.$row['Number1'].')</div>';

}

所以它会像这样出来......

<div class="result">18:00:00 (8)</div>
<div class="result">18:30:00 (5)</div>
<div class="result">19:00:00 (6)</div>

但是我还想表明 18:15:00 有 0 个成年人。我尝试添加一些这样的 if 语句

if (($row['Time'] == '18:15:00') and ($row['Number1'] < '10')) {
echo '<div class="result">'.$row['Time'].' ('.$row['Number1'].')</div>';
}
else {
echo '<div class="result">18:15:00 (0)</div>';
}

但它一直在循环。有人可以告诉我哪里出错了吗?

4

3 回答 3

0

如果要break跳出循环语句,可以使用break语句:

while(condition){
    if(conditionMet){
        break;
    }
}
于 2013-03-30T00:58:12.587 回答
0

我不太确定您要做什么,但也许就是这样:

if ($row['Number1'] < '10') {
  echo '<div class="result">'.$row['Time'].' ('.$row['Number1'].')</div>';
} elseif ($row['Time']) == '18:15:00') {
  echo '<div class="result">18:15:00 (0)</div>';
}
于 2013-03-30T01:23:16.997 回答
0

改变:-

if (($row['Time'] == '18:15:00') and ($row['Number1'] < '10')) 
{
echo '<div class="result">'.$row['Time'].' ('.$row['Number1'].')</div>';
}
else 
{
echo '<div class="result">18:15:00 (0)</div>';
}

if ($row['Number1'] < '10') 
{
echo '<div class="result">'.$row['Time'].' ('.$row['Number1'].')</div>';
}
elseif(($row['Time']) == '18:15:00') 
{
echo '<div class="result">18:15:00 (0)</div>';
}
于 2013-03-30T07:00:47.100 回答