2016-12-05 82 views
-3

当我添加if语句,该语句将存储在表中的时间值与当前时间进行比较时,PHP将引发错误。找不到解决方案。感谢您的帮助。这里是代码:在foreach PDO中运行if语句

<?php 
//All database times that are 1 hour before stating will be locked in browser not able to reserve any more 
$currtime= date("h:i"); 

foreach ($pdo->query($sql) as $row) { 
    echo '<tr>'; 
    if ($row['time']-$currtime=<-1) { 
     echo '<td>'.$row['time']='passed'.'</td>' 
    }; 
    else { 
     echo '<td>'. $row['time'] . '</td>'; 
    } 
    //the following part is just so you know what follows in my code within the loop 

    if($row[$selected_day]=='available') { 
     echo '<td>'. '<a href="read.php?id='.$row['id'] . '&s_t_id='.$row['schd_tut_id'].'&dat='.$selected_day .'">available</a>'; 
    } else { 
     echo '<td>'. $row[$selected_day] . '</td>'; 
    } 
} 
?> 
+0

,如果你向我们展示了误差会更容易,但可能是这样的:$ currtime = < - 1那是什么“? – FLX

+0

';'在'else' - >'}之前; else'。你也无法用这种方式计算时差。 –

回答

0

@ Sougata玻色,感谢的人,这错了;在结束大括号之后,页面的原因与该等号不一起加载。现在一切正常。谢谢。 下面的代码只是工作对我罚款:

<?php 
//All database times that are 1 hour before stating will be locked in browser not able to reserve any more 
$currtime= date("h:i"); 

foreach ($pdo->query($sql) as $row) { 
    echo '<tr>'; 
    if ($row['time']-$currtime<=-1) { 
     echo '<td>'.$row['time']='passed'.'</td>' 
    ;} 
    else { 
     echo '<td>'. $row['time'] . '</td>'; 
    } 
    //the following part is just so you know what follows in my code within the loop 

    if($row[$selected_day]=='available') { 
     echo '<td>'. '<a href="read.php?id='.$row['id'] . '&s_t_id='.$row['schd_tut_id'].'&dat='.$selected_day .'">available</a>'; 
    } else { 
     echo '<td>'. $row[$selected_day] . '</td>'; 
    } 
} 
?>