php - Why does "If" runs only for the first loop of "foreach" block? -
i making website , wrote following code display patient's prescriptions , make part of count down system.
<?php $stmt = "select * `prescriptions`, `drugs` prescriptions.drug = drugs.id , patient = '".$_session['username']."'"; $result = mysqli_query($mysqli,$stmt); while ($x = mysqli_fetch_array($result)) {$pa[] = $x;} foreach ($pa $i){ $lasttaken = strtotime($i['lasttaken']); echo "lasttaken =".date('h:i:s', $lasttaken)."\n"; $dosage = ($i['dosage'] - 1) * 3600; $nexttakein = date('h:i:s', $lasttaken) + date('h:i:s', $dosage) + 3600; echo "dosage =".date('h:i:s', $dosage)."\n"; echo "next =".date('h:i:s', $nexttakein)."\n"; echo "time=".date('h:i:s', time() +3600); $timeleft = date('h:i:s', $nexttakein) - date('h:i:s', time() + 3600); echo "timeleft = " .date('h:i:s', $timeleft)."<br>"; printf("<tr id='x'class='t'><td id='y'>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",$i['name'],$i['dosage'], $i['doctor'], date('h:i:s d-m', $nexttakein), date('h:i:s',$timeleft)); if ($timeleft <= 0) { $id = $i['id']; $timeleft = time() + 3600; $sql = "update prescriptions set prescriptions.lasttaken = current_timestamp prescriptions.id = $id"; $stmt3 = $mysqli->prepare($sql); $stmt3->execute(); } } ?>
the thing reason enters if block first prescription every time if isn't less 0 never next.
why that? thank ^_^
Comments
Post a Comment