我想从mysql表中填充下拉值。我使用了加载事件
在html页面中,但我不知道此代码不起作用。
HTML页面
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#select1").load("se2.php");
});
});
</script>
</head>
<body>
<select id="select1"></select>
<button>Get External Content</button>
</body>
</html>
se2.php
<?php
$dbhandle = mysql_connect("localhost","root","")
or die("Unable to connect to MySQL");
$selected = mysql_select_db("student",$dbhandle)
or die("Could not select examples");
$result1 = mysql_query("SELECT column1 FROM information");
while($row=mysql_fetch_array($result1))
{
if($row['column1']!=NULL)
{
echo "<option value='$row[column1]'>$row[column1]</option>";
}
}
?>
最佳答案
改变这个
<select id="select1"></select>
对此
<div id="select1"></div>
并将select标签添加到php
$result1 = mysql_query("SELECT column1 FROM information");
echo "<select>";
while($row=mysql_fetch_array($result1))
{
if($row['column1']!=NULL)
{
echo "<option value='$row[column1]'>$row[column1]</option>";
}
}
echo "</select>";
并给按钮一个ID
<button id="button">Get External Content</button>