全部,
根据数据库结果,我有一个选项是动态的下拉列表。当用户从此下拉列表中进行选择时,我希望div显示与此选择相关的结果(也从数据库中提取,链接到选择)。我有这个混合的html / php / javascript既没有显示任何错误,也没有做我需要的东西。我的问题是,这里有什么问题:
$result_stat_query = ("SELECT statid, stat_name FROM stats");
$result_stat = $DB_con->query($result_stat_query);
if(!$result_stat)
{
$DB_con->debug_mode('query', 'error', '#Query Failed<br/>'.$DB_con->error);
return false;
}
echo "<select name='stat_id' onchange='filterContent();'>";
while ($row_stat = $result_stat->fetch()) {
unset($statid, $stat_name);
$statid = $row_stat['statid'];
$stat_name = $row_stat['stat_name'];
//declared variables now to set the javascript so that the content only appears for each selected drop down item
?>
<script>
function filterContent() {
var user = document.getElementById("stat_id").value;
var contentA = document.getElementById("contentA");
if(user=="<?php $statid; ?>") {
contentA.style.display="block";
}
</script>
<?php
//now grab each id and stat name and display in the drop down
echo '<option value="'.$statid.'">'.$stat_name.'</option>';
}
echo "</select>";
?>
<div id="contentA">
<?php echo "<p>Stat name= $stat_name</p>"; ?>
</div>
修改
我试过这个,但它仍然无效: 在头脑中:
<script>
function filterContent() {
var user = document.getElementById("stat_id").value;
var contentA = document.getElementById("contentA");
contentA.style.display="block";
</script>
我的php,html部分看起来像这样:
$result_stat_query = ("SELECT statid, stat_name, speed, strength, health, temper, armor, alertness, intelligence, emotion FROM character_stats");
$result_stat = $DB_con->query($result_stat_query);
if(!$result_stat)
{
$DB_con->debug_mode('query', 'error', '#Query Failed<br/>'.$DB_con->error);
return false;
}
echo "<select name='stat_id' onchange='filterContent();'>";
while ($row_stat = $result_stat->fetch()) {
unset($statid, $stat_name);
$statid = $row_stat['statid'];
$stat_name = $row_stat['stat_name'];
//declared variables now to set the javascript so that the content only appears for each selected drop down item
?>
<?php
//now grab each id and stat name and display in the drop down
echo '<option value="'.$statid.'">'.$stat_name.'</option>';
}
echo "</select>";
?>
<div id="contentA">
<?php echo "<p>Stat name= $stat_name</p>"; ?>
</div>