我正在尝试使用 jEditable 选择更新字段。我正在从我的数据库中提取 jEditable 选择的数据。查询数组如下所示:
Array ([0] => Array([conference_id] => 1 [conference_name] => Allegheny Mountain) 等等……</p>
我想在下拉列表中显示会议名称,但使用会议 ID 作为插入数据库的值。目前我得到的只是一个选择值的空白列表。有人对我如何让它做我想做的事情有任何想法吗?
这是我在下面的代码:
<?php
try {
// Connect to the database
$db = new PDO('mysql:host=localhost;dbname=football;', 'fbdbuser', 'fbdbpass');
} catch(PDOException $e) {
echo $e->getMessage();
}
try {
// Retrieve all team information
$query = $db->prepare("SELECT * FROM team ORDER BY team_name");
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
// Retrieve all conferences
$query_conference = $db->prepare("SELECT conference_id, conference_name FROM conference ORDER BY conference_name");
$query_conference->execute();
$result_conference = $query_conference->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="js/jquery.js"></script>
<script src="js/jeditable.js"></script>
<script>
$(document).ready(function() {
$(".editable_conference").editable('update_conference.php', {
data : '<?php echo json_encode($result_conference); ?>',
type : 'select',
indicator : 'Saving...',
submit : "OK",
tooltip : "Click to Update"
});
});
</script>
<title></title>
</head>
<body>
<h1 align="center">Update Teams Below</h1>
<?php //echo '<pre>' . print_r($result_conference) . '</pre>'; ?>
<table align="center" width="90%" border="1" cellpadding="5" cellspacing="0">
<tr bgcolor="#CCCCCC">
<td>TEAM</td>
<td>MASCOT</td>
<td>STATE</td>
<td>CONFERENCE</td>
<td>DISTRICT</td>
<td>CLASS</td>
</tr>
<?php foreach ($result as $value) { ?>
<tr>
<td><?php echo $value['team_name']; ?></td>
<td class="editable_mascot" id="<?php echo $value['team_id']; ?>"><?php echo $value['team_conference']; ?></td>
<td class="editable_state" id="<?php echo $value['team_id']; ?>"><?php echo $value['team_mascot']; ?></td>
<td class="editable_conference" id="<?php echo $value['team_id']; ?>"><?php echo $value['team_state']; ?></td>
<td class="editable_district" id="<?php echo $value['team_id']; ?>"><?php echo $value['team_district']; ?></td>
<td class="editable_classification" id="<?php echo $value['team_id']; ?>"><?php echo $value['team_classification']; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>