I'm doing an availability system. I need to display the records in a table.
My system is basically about real estate which tracks if a property is available or not. Sample is I have 20 floors in condominium each floor has 10 units so I need to loop the number of floors and also display each unit under a specific floor.
1st flr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
2nd flr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
This is what I've tried so far:
<table class="table table-bordered">
<?php
for($i=0; $row3 = $stmt3->fetch(); $i++){
$floor = $row3['floor'];
?>
<tr>
<td><?php echo $floor; ?></td>
<?php
for($i=0; $row4 = $stmt4->fetch(); $i++){
$unit_code = $row4['unit_code'];
?>
<td><?php echo $unit_code; ?></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
But it's just display all the records in the first floor.
This is what actually happened:
1st flr| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
2nd flr
What could be the correct way to achieve my needs? Any ideas? I would gladly appreciate your help. Thanks.
UPDATE:
$stmt3 = $conn->prepare( "SELECT DISTINCT floor
FROM tblunitsmaster
WHERE project_code = :code" );
$stmt3->execute(array(':code' => $code));
$stmt4 = $conn->prepare( "SELECT unit_code
FROM tblunitsmaster
WHERE project_code = :code
AND floor = :floor
AND sub_project_code = 'SUB-AX0001'" );
unit_codeis printed before thefloorcan change. One way to solve this is to change your query to fetchunit_codebyfloor.