<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<select>
<?php
//造链接对象
$db=new MySQLi("localhost","root","123456","xinjian");
//判断是否出错
!mysqli_connect_error() or die("链接失败");
//写sql语句
$sql="select * from nation";
//执行sql语句
$result=$db->query($sql);
//处理数据
$attr = $result->fetch_all();
//遍历并显示
for ($i=0;$i<count($attr);$i++)
{
list($code,$name)=$attr[$i];
echo "<option value='{$code}'>{$name}</option>";
}
?>
</select>
</body>
</html>
![](https://images2015.cnblogs.com/blog/865473/201603/865473-20160324140701433-1699410019.png)