I'm trying to fetch row so i can print it on my table. But the problem is that, the code only runs on the 1st while loop. After it fetch all the rows in the table, it stops there.
`Assuming that I have 5 rows in my tblUnit
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
echo " <script type'text/javascript'> alert('1');</script>";
$unitStatus = $r['unitStatus'];
$unitNumber = $r['unitNumber'];
$floorNumber = $r['floorCode'];
$unitType = $r['unitType'];
$t = $db->query("select floorLevel from tblFloors where floorID = $floorNumber");
$w = $db->query("select unitTypeName from tblUnitType where unitTypeID = $unitType");
while ($u = $t->fetch(PDO::FETCH_ASSOC)) {
echo " <script type'text/javascript'> alert('2');</script>";
$floorLevel = $u['floorLevel'];
while ($x = $w->fetch(PDO::FETCH_ASSOC)) {
echo " <script type'text/javascript'> alert('3');</script>";
....
...
..
}
}
}
The output(In alert box):
1
1
1
1
1
I'm using MS SQL Server for my database.
whiles .. are you sure, one query usingJOINwouldn't simplify this?