Hi,
I am a noob in php and mysql, and I am trying to create a simple room reservation system for my school.
I wanted to create a table with the available and occupied hours like this:
However, I am not getting it right.
For each hour I chose to identify with a letter, like:
a->8:00-8:50; b->9:00-9:50; c->10:00-10:50; d-> 11:00-11:50
I’ll get the occupied hours of a certain date in my mysql database like this:
$con = db_connect();
$result=mysqli_query($con,"SELECT * FROM reservations WHERE data = '$mydate' ORDER BY hour");
while($row = mysqli_fetch_array($result)){
$person = $row['person'];
$room = $row['room'];
$hour = $row['hour'];
$convertedhour = converthour($hour); // convertes the letter to correspondent hour
echo
"<tr>
<td>$convertedhour</td>
<td>$person</td>
<td>$room</td>
</tr>";
}
Now my question is how to put lines when that hour is not occupied?
I’ve tried this:
$con = db_connect();
$result=mysqli_query($con,"SELECT * FROM reservations WHERE data = '$mydate' ORDER BY hour");
$hours=array("a","b","c","d);
$arrlength=count($hours);
while($row = mysqli_fetch_array($result)){
for($j=0; $j<$arrlength; $j++){
if ( $hours[$j]; == $row['hour'];){ // if it exists in reservation table, therfore is occupied
$person = $row['person'];
$room = $row['room'];
$hour = $row['hour'];
// How to advance to the next element of row?
} else{ //if doesnt match, hour is available
$person = “<a href='add_reserva.php?hora=$hora&mydate=$mydate'>Requisitar</a></”;
$room = “”;
$hour = $hours[$j];
}
$convertedhour = converthour($hour); // convertes the letter to correspondent hour
echo
"<tr>
<td>$convertedhour</td>
<td>$person</td>
<td>$room</td>
</tr>";
}
}
But it does not work because I dont know how to advance to the next row …
Can you help me please??