php - jqgrid 从一个网格更新两个表

标签 php mysql jqgrid

我在一个网格中显示了两个表(通过 LEFT JOIN),我想知道有没有办法为同一网格中的两个表实现内联编辑功能?

即: 当主网格表更新时:

onSuccess { table_name, {column1=value1,column2=value2,..}}

不一定是上述情况 - 我在这里寻找想法和逻辑......

我知道 jqGridPHP 套件中有 setAfterCrudAction 函数,但从整个套件中我只需要这个功能...所以我正在尝试实现它我自己在你的帮助下

感谢任何想法,谢谢

最佳答案

Example显示了如何在使用连接时更新字段(检查“PHP 网格”选项卡,顺便说一句 jqgrid-php 是免费的):

<?php

class jqOperBasic extends jqGrid
{
    protected function init()
    {
        $this->table = 'tbl_order_item';

        $this->query = "
            SELECT {fields}
            FROM tbl_order_item i
                JOIN tbl_books b ON (i.book_id=b.id)
            WHERE {where}
        ";

        #Set columns
        $this->cols = array(

            'item_id' => array('label' => 'ID',
                'db' => 'i.id',
                'width' => 10,
                'align' => 'center',
                'formatter' => 'integer',
            ),

            'order_id' => array('label' => 'Order id',
                'db' => 'i.order_id',
                'width' => 15,
                'align' => 'center',
                'formatter' => 'integer',
            ),

            'name' => array('label' => 'Book name',
                'db' => 'b.name',
                'width' => 30,
                'editable' => true,
                'editrules' => array('required' => true),
            ),

            'price' => array('label' => 'Price',
                'db' => 'i.price',
                'width' => 15,
                'align' => 'center',
                'formatter' => 'integer',
                'editable' => true,
                'editrules' => array('required' => true,
                    'integer' => true,
                    'minValue' => 1,
                    'maxValue' => 3000
                ),
            ),
        );

        #Set nav
        $this->nav = array('edit' => true, 'edittext' => 'Edit');
    }

    #Save columns to different tables
    protected function opEdit($id, $upd)
    {
        #Server-side validation
        if(strlen($upd['name']) < 5)
        {
            #Just throw the exception anywhere inside the oper functions to stop execution and display error
            throw new jqGrid_Exception('The book name is too short!');
        }

        #Get editing row
        $result = $this->DB->query('SELECT * FROM tbl_order_item WHERE id=' . intval($id));
        $row = $this->DB->fetch($result);

        #Save book name to books table
        $this->DB->update('tbl_books', array('name' => $upd['name']), array('id' => $row['book_id']));
        unset($upd['name']);

        #Save other vars to items table
        $this->DB->update('tbl_order_item', $upd, array('id' => $id));
    }
}

关于php - jqgrid 从一个网格更新两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14776905/

相关文章:

php - 语言翻译不正确(例如阿拉伯语)

php - 根据文件名使用 php/sql 加载 excel 文件

javascript - jqGrid 免费 : Help on design of handling multiple yearly calendars with monthly breakdown data

jquery - 如何在编辑表单中更改只读字段的背景颜色

java - 如果我使用 Java 而不是 PHP,这个 URL 应该指向哪里?

php - 在给定位置(重新)开始时,如何正确计算 ProgressBar 中的 ETA?

php - 从mysql行获取信息

php - 如何生成动态加载数据库的所有可能结果?

PHP MYSQL - 127.0.0.1 和 localhost 之间的区别

MYSQL查询,是否可以在每个产品的第7位之后找到一个 "E"?