这是我的数据:
select * from extension;
+---------+-------+
| ext_num | name |
+---------+-------+
| 574324 | joe |
| 564334 | sarah |
| 987652 | pete |
+---------+-------+
3 rows in set (0.00 sec)
我正在尝试插入
selected="selected"
动态地同时遍历表。
<?php
$mysqli = new mysqli("localhost", "user", "pass", "db");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if ($result = $mysqli->query("SELECT * FROM extension")) {
print "<select>\n<option>select a value</option>\n";
while ($row = $result->fetch_assoc())
{
printf ("<option value=\"%s\">%s</option>\n", $row["ext_num"], $row["name"]);
}
print '</select>';
}
?>
实现以下内容的最简单/有效的方法是什么:
<option value="987652" selected="selected">pete</option>
(特别是:selected="selected")
使用与上述类似的代码进入我的循环?