我正在尝试将我的代码从 mysql 更改为 mysqli,但我在更改这段代码时遇到了麻烦:
while($sqlrow = mysql_fetch_array($sqlresult))
{
$room = $sqlrow['Room'];
$roomHTML .= "<option value='".$room."'>" . $room . "</option>".PHP_EOL;
}
echo $roomHTML;
我在 mysqli 代码中没有变量 $sqlrow ,下面,我该如何将行更改$room = $sqlrow['Room'];
为以下内容:
完整代码:
$building = isset($_POST['building']) ? $_POST['building'] : '';
$sql = "SELECT Room FROM Room WHERE Building = ?";
$sqlstmt=$mysqli->prepare($sql);
$sqlstmt->bind_param("s",$building);
$sqlstmt->execute();
$sqlstmt->bind_result($dbRoom);
$roomHTML = "";
while($sqlstmt->fetch()) {
$room = $sqlrow['Room'];
$roomHTML .= "<option value='".$room."'>" . $room . "</option>".PHP_EOL;
}
echo $roomHTML;
$sqlstmt->execute();
上面的代码试图在下拉菜单中显示与它们所属的建筑物匹配的所有房间。
谢谢