在jqgrid中添加,编辑和删除使用CodeIgniter反映在数据库中的数据

问题描述:

As with other questions, Oleg's assistance with jqgrid-related queries are very much helpful and appreciated. Through his answers I have been able to inch towards my goal; though what's bothering me is the editurl property. On most demos it's just someurl.php.

Oleg also said that this php file contains the instructions(mysql) to edit the database using data sent to it by jqgrid. By using Firebug I've seen that it is indeed posting the data entered but it results to Error 404 all the time. I've tried placing the someurl.php everywhere in the CI folder. And given that, I'm still not sure what to write in the someurl.php.

Can anyone please help? I've been stuck on implementing Add, Edit, and Delete the whole day.

与其他问题一样,Oleg对jqgrid相关查询的帮助非常有帮助和赞赏。 通过他的回答,我已经能够朝着我的目标前进; 虽然困扰我的是editurl属性。 在大多数演示中,它只是someurl.php。 p>

Oleg还说这个php文件包含使用jqgrid发送给它的数据来编辑数据库的指令(mysql)。 通过使用Firebug我已经看到它确实发布了输入的数据,但它始终导致错误404。 我已经尝试将someurl.php放在CI文件夹中的任何地方。 鉴于此,我仍然不确定在someurl.php中写什么。 p>

任何人都可以帮忙吗? 我一直坚持实施添加,编辑和删除一整天。 p> div>

Thanks to the suggestion of Ballantine, I finally solved this.

It turns out that someurl.php is indeed relative to index.php and is thus found at the controllers folder via CodeIgniter.

From there, it's just a matter of using someurl.php as a controller:

Here I took advantage of using the POST sent from the view page that contains jqGrid. They are the oper, clientCode, clientName, and id in my case.

Furthermore, on the query part, I could've used something like $this->db->update via CodeIgniter but I since I'm a beginner at mySQL, I might as well try to familiarize myself with the syntax.

And from here on, you could continue nesting this for the add and delete cases. I hope this helps someone!

else if($_POST["oper"] == 'edit'){


        $newCode = $_POST["clientCode"];
        $newName = $_POST["clientName"];
        $id = $_POST["id"];



        $this->db->query("UPDATE tblclient SET clientCode = '$newCode', clientName = '$newName' WHERE clientCode = '$id' LIMIT 1");

    }