javascript - Editablegrid mysql 绑定(bind)未更新

标签 javascript php mysql editablegrid

我正在使用 editablegrid 和 mysql。它将数据绑定(bind)并显示到我的网格。但是,当我尝试编辑或更新网格时,它失败了。

下面是我的loaddata的一些代码,

$grid->addColumn('CertificateNo', 'CertificateNo', 'integer', NULL, false); 
$grid->addColumn('ID', 'ID', 'integer');
$grid->addColumn('QuizNo', 'Test No', 'integer');  
$grid->addColumn('Received', 'Received', 'boolean');  
$grid->addColumn('DateReceived', 'Date Received', 'datetime'); 

以下是更新脚本的代码:

    // Get all parameters provided by the javascript
$colname = $mysqli->real_escape_string(strip_tags($_POST['colname']));
$id = $mysqli->real_escape_string(strip_tags($_POST['id']));
$coltype = $mysqli->real_escape_string(strip_tags($_POST['coltype']));
$value = $mysqli->real_escape_string(strip_tags($_POST['newvalue']));
$tablename = $mysqli->real_escape_string(strip_tags($_POST['tablename']));
    / This very generic. So this script can be used to update several tables.
$return=false;
if ( $stmt = $mysqli->prepare("UPDATE ".$tablename." SET ".$colname." = ? WHERE id = ?")) {
    $stmt->bind_param("si",$value, $id);
    $return = $stmt->execute();
    $stmt->close();

下面是 javascript 的一部分,它将值传递给我的 update.php 脚本。

    function updateCellValue(editableGrid, rowIndex, columnIndex, oldValue, newValue, row, onResponse)
{      
    $.ajax({
        url: 'update.php',
        type: 'POST',
        dataType: "html",
        data: {
            tablename : editableGrid.name,
            id: editableGrid.getRowId(rowIndex), 
            newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue, 
            colname: editableGrid.getColumnName(columnIndex),
            coltype: editableGrid.getColumnType(columnIndex)            
        },
        success: function (response) 
        { 
            // reset old value if failed then highlight row
            var success = onResponse ? onResponse(response) : (response == "ok" || !isNaN(parseInt(response))); // by default, a sucessfull reponse can be "ok" or a database id 
            if (!success) editableGrid.setValueAt(rowIndex, columnIndex, oldValue);
            highlight(row.id, success ? "ok" : "error"); 
        },
        error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
        async: true
    });

该模板附带了 javascript editablegrid-2.0.1。我注意到问题与主键有关。在 www.editablegrid.net 上可以找到的演示中,表有主键 ID,而我的表有 CertificateNo,但我表中的 ID 不是主键。

所以我改变了

$grid->addColumn('ID', 'ID', 'integer', NULL, false);

$grid->addColumn('CertificateNo', 'CertificateNo', 'integer', NULL, false); 

现在我无法更新网格。

最佳答案

我也遇到了同样的问题,你可以在loaddata.php中看到这段代码

$grid->addColumn('action', 'Action', 'html', NULL, false, 'id'); 

将最后一列的“id”替换为“CertificateNo”,如下所示

$grid->addColumn('action', 'Action', 'html', NULL, false, 'CertificateNo');

然后重新加载页面以查看更改。

关于javascript - Editablegrid mysql 绑定(bind)未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14373702/

相关文章:

php - 如何按日期为谷歌图表迭代数据库值

javascript - 更改分辨率时自动更改 css

javascript - 如何从数组数组中创建一个新数组,仅选择具有所需索引的元素

php - 带有条件的mysql查询计数,结果为数字

PHP:以递归方式填充数组

php:如果数据库中的字段不为空,则显示 html

javascript - pdfMake无法读取未定义的属性 '_calcWidth'

javascript - 如何使用 typescript 在 Ionic 2.0 中包含 Angular 模式形式

mysql - 如何在本地将 Airflow 连接到 SQLite?

php - 在 mySQL 5 TABLES 中使用 INNER JOIN 删除多个表中的多行