mysql - PHP/SQL How can I make my query include results that has no records in another table yet? -
i have 2 php codes performs room search. user specifies no. of beds, check in date , check out date. first code retrieves rooms corresponding number of beds. second code checks if room has existing booking, if , booking dates not clash user input dates room displayed, if not have existing booking displayed.
my first php code:
$sql = "select rooms.rid, beds, orientation, price rooms (beds = $nofbeds)"; if ($rorientation != "") { $sql .= " , orientation = '$rorientation'"; } $results = mysqli_query($conn, $sql) or die ('problem query' . mysqli_error($conn));
my second php code:
<?php while ($row = mysqli_fetch_array($results)) { $sql2 = "select rid, checkin, checkout bookings"; $results2 = mysqli_query($conn, $sql2) or die ('problem query' . mysqli_error($conn)); $row2 = mysqli_fetch_array($results2); if ($row["rid"] == $row2["rid"]) { if (($cindate < $row2["checkin"] && $coutdate <= $row2["checkin"]) || (($cindate >= $row2["checkout"] && $coutdate > $row2["checkout"]))) { ?> <tr> <td><?php echo $row["rid"]?></td> <td><?php echo $row["beds"]?></td> <td><?php echo $row["orientation"]?></td> <td><?php echo $row["price"]?></td> </tr> <?php } } } ?>
currently working right in regards filtering out clashing dates filtering out rooms not have existing booking. problem encountered code not seem work multiple bookings same room id (rid) right filtering dates regarding first booking.
this booking table: http://imgur.com/dgoko1f
this rooms table: http://imgur.com/ed5kfes
you can use,
if($result != null) { // execute code } else { // give null values or error }
other way is, if(count($result) > 0)
.
this way can error free results.
Comments
Post a Comment