mardi 27 janvier 2015

How to have a if statement within a while loop?


<?php
if ($result->num_rows > 0) {
<table>
<tr>
<th>Guest ID</th>
<th>Arrival Date</th>
<th>Number of Nights</th>
<th>Departure Date</th>
<th>Check Out?</th>
<th></th>

</tr>
</fieldset>";
// output data of each row
while ($row = $result->fetch_assoc()) {
$today = date("Y-m-d");
$departure_date = new DateTime($row['arrivaldate']);
$departure_date->add(new DateInterval('P' . $row["numberOfNights"] . 'D'));
echo "<tr><td>" . $guestid .
"</td><td><center>" . $row["arrivaldate"] . "</center>" .
"</td><td><center>" . $row["numberOfNights"] . "</center>" .
"</td><td><center>" . $departure_date->format('Y-m-d') . "</center>" . " </td></td>" . "</td><td>" ;

if ($departure_date == $today){
echo '<td>' . "<a href='doCheckOut.php?guestid=" . $guestid . "'>Check Out</a>" . '</td>';
}
}
echo "</table>";
} else {
echo "0 results";
}
?>


As seen from my code above, I want to display the link to check out if a guest's departure date is as of today's date, but it is not working. How would I go about doing it?


Aucun commentaire:

Enregistrer un commentaire