jEditable选择数据源 [英] jEditable Select Data Source

查看:90
本文介绍了jEditable选择数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to update a field using a jEditable select. I am pulling the data for the jEditable select from my database. The query array looks like this:

Array([0] => Array([conference_id] => 1 [conference_name] =>阿勒格尼山(Allegheny Mountain))等...

Array ([0] => Array([conference_id] => 1 [conference_name] => Allegheny Mountain) etc…

我想在下拉列表中显示会议名称,但是将会议ID用作插入数据库的值.目前,我得到的只是选择值的空白列表.有人对我如何让它做自己想做的有任何想法吗?

I want to show the conference name in the drop down but use the conference id as the value that gets inserted into the database. Currently all that I am getting is a blank list of select values. Does anybody have any ideas on how I can get this to do what I want?

这是我下面的代码:

<?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); ?>,并且此变量是多维数组.您可以将其设为一维,然后将其传递给正常工作的数据.

You are using <?php echo json_encode($result_conference); ?> and this variable is multi-dimesional array. You can make it one dimensional and pass it data that works fine.

$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

这篇关于jEditable选择数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆