我试图获取行,以便将其打印在桌面上。但问题是,代码只在第一个while循环上运行。在获取表中的所有行后,它就会停在那里。
`假设我的tblUnit中有5行
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>";
....
...
..
}
}
}
输出(In alert box
):
1
1
1
1
1
我正在使用MS SQL Server作为我的数据库。
答案 0 :(得分:2)
可能是一个字符串评估问题尝试这种方式
$t = $db->query("select floorLevel from tblFloors where floorID = " . $floorNumber .";");
$w = $db->query("select unitTypeName from tblUnitType where unitTypeID = " . $unitType . ";");
或
$t = $db->query("select floorLevel from tblFloors where floorID = '$floorNumber' ;");
否则您的$ floorNumber不包含预期结果