我正在尝试创建一个动态下拉列表,根据下拉列值显示输出。 我一直在尝试运行此代码,但我收到此警告。我不知道为什么。 警告:mysqli_fetch_assoc()要求参数1为mysqli_result,第18行的C:\ wamp64 \ www \ testing \ load_data.php中给出布尔值
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "dd_vals");
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!$connection) {
echo "connection failed";
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<select id="category">
<?php
$sql = "select * from dd_vals";
$result = mysqli_query($connection,$sql);
while($row = mysqli_fetch_assoc($result)){
$index = $row['index'];
$category = $row['category'];
?>
<option value="<?php echo $index; ?>"><?php echo $category; ?>
</option>
<?php } ?>
</select>
<div id="stuff"></div>
<script>
$(document).ready(function(){
$('#category').change(function(){
var index = $(this).val();
$('#stuff').load("load_data.php", {
index : index
});
});
});
</script>
</body>
</html>
这是加载数据文件
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "dd_vals");
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!$connection) {
echo "connection failed";
}
$index = $_POST['index'];
$sql = "select * from dd_vals where index = $index LIMIT 1";
$result = mysqli_query($connection, $sql);
while($row = mysqli_fetch_assoc($result)){
echo $row['dd_val'];
}
?>