簡體   English   中英

EditableGrid MySQL綁定未更新

[英]Editablegrid mysql binding not updating

我在MySQL中使用editablegrid。 它綁定並顯示數據到我的網格。 但是,當我嘗試編輯或更新網格時卻無法這樣做。

以下是我的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');

然后重新加載您的頁面以查看更改。

update.php使用$ _POST ['id'],也許您應該將其更改為$ _POST ['CertificateNo']並將該ID作為另一列進行處理,因為它不再是主鍵。

我有同樣的問題。 您必須在js / demo.js中進行更改

function DatabaseGrid() 
{ 
    this.editableGrid = new EditableGrid("HERE!!! Chage to name of your sql table", {...

並將您的CertificateNo重命名為“ id”或在其之前重新命名,因為網格在很多地方都可以使用它,因此很難在任何地方進行更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM