gpt4 book ai didi

javascript - 在 HTML 下拉菜单中显示 PHP 变量

转载 作者:行者123 更新时间:2023-11-30 10:24:58 26 4
gpt4 key购买 nike

我有一个装有安全问题和答案的 SQL 数据库。我需要在 html 下拉列表中显示它们。我以为我可以用 while 循环填充下拉字段,但我无法让它工作。

知道这有什么问题吗?

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<?php

$conn = mysql_connect("localhost","root","")or die (mysql_error());

mysql_select_db("assignment_3", $conn);

$data = "select securityQuestion, securityAnswer from securityquestiontable";

$result = mysql_query($data, $conn) or die (mysql_error());

while ($row = mysql_fetch_assoc($result)) {
print "<select>";
print "<option value=""";
print "disabled="disabled" selected="selected">";
print "Please Select your Undergraduate School";
print "</option>";
print "<option value="1">";
print $row["securityQuestion"];
print "</option>";
print "<option value="2">";
print $row["securityAnswer"];
print "</option>";
print "</select>";
}

?>

</body>
</html>

最佳答案

您需要循环的打印语句。每次循环时,您都在创建一个新菜单。试试这个:

print "<select>";
while ($row = mysql_fetch_assoc($result)) {
print "<option value=""";
print "disabled="disabled" selected="selected">";
print "Please Select your Undergraduate School";
print "</option>";
print "<option value="1">";
print $row["securityQuestion"];
print "</option>";
print "<option value="2">";
print $row["securityAnswer"];
print "</option>";
}
print "</select>";

关于javascript - 在 HTML 下拉菜单中显示 PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20038821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com