gpt4 book ai didi

php - jEditable 选择数据源

转载 作者:行者123 更新时间:2023-11-29 14:18:41 25 4
gpt4 key购买 nike

我正在尝试使用 jEditable 选择来更新字段。我正在从数据库中提取 jEditable 选择的数据。查询数组如下所示:

数组([0] => 数组([conference_id] => 1 [conference_name] => 阿勒格尼山)等...

我想在下拉列表中显示 session 名称,但使用 session 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>

最佳答案

你应该了解jeditable的现象.

您正在使用<?php echo json_encode($result_conference); ?>并且这个变量是多维数组。您可以将其设置为一维并向其传递可以正常工作的数据。

$result_conference = $query_conference->fetchAll(PDO::FETCH_ASSOC);
$conf = array();
foreach($result_conference as $val){
$conf[$val['conference_id']] = $val['conference_name'];
}

使用$conf变量代替 $result_conference

关于php - jEditable 选择数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12153000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com