2016-12-05 83 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>'; 
    } 
} 
?>