I have a SlickGrid set up, it is reading data from my database with PHP, my problem is arising when i try to save the data back to my database, I am trying to use JSON to give me an array that I can then use to write back to the database, i have see this thread explaining this:

SlickGrid设置,它是我从数据库读取数据使用PHP,我的问题是引起当我试图将数据保存到数据库中,我试图使用JSON数组给我,然后我可以使用写回数据库,我有看到这个帖子解释:

Saving changes in SlickGrid

储蓄的变化SlickGrid

So I have the hidden form element in my code, and am using JSON to encode the data variable, the assign it to the data hidden input on the form, this form posts to a page called save_price.php, the trouble is when I print_r, or var_dump the data variable, I get null as an output, I think it might be something to do with how I am using PHP to add the content into the data variable, either that or I am doing something really obviously wrong, hopefully you can see what the problem is, there isn't a great deal of documentation online about retrieving/saving to a db with PHP, so I'm kinda stuck banging my head against the wall on this one, here's my code:

我在代码中有一个隐藏的表单元素,正在使用JSON对数据变量进行编码,将它分配给表单上的隐藏输入,这个表单将发送到一个名为save_price的页面。php,麻烦的是当我print_r,或var_dump数据变量,得到零作为输出,我想这可能与我如何使用php将内容添加到数据变量,或者是我做一些真正显然错了,希望你能看到的问题是什么,没有大量的文档在线检索/保存数据库使用php,所以我有点困拿我的头往墙上撞,这是我的代码:

1 个解决方案

#1


4

Ok so I found the problem, just incase anyone is struggling to get this all to work, here is the working code, it gets data from a database, then sends the changed data to another page for processing, it nees a little bit of refinements, that will happen once I've got it all implemented:

含有所以我发现这个问题,有人努力让这一切工作,这是工作代码,数据从一个数据库,然后将更改后的数据发送给另一个页面进行处理,它需要雇一些改进,会发生,一旦我有它所有的实现:

<?php 
include("includes/check_session.php");
require_once('includes/functions.php');
require_once('includes/config.php');

$data = '';
$i = 0;

$query = "
    SELECT * FROM `prices`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $data .= '
        data['.$i.'] = {
            id: "'.$row['id'].'",
            title: "'.$row['title'].'",
            duration: "'.$row['duration'].'",
            percentComplete: "'.$row['percentComplete'].'",
            start: "'.$row['start'].'",
            finish: "'.$row['finish'].'",
            effortDriven: "'.$row['effortDriven'].'"
        };
    ';

    $i++;

echo $data;
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset=utf-8>

    <?php // include("includes/cms_head_scripts.php"); ?>
    <link rel="stylesheet" href="css/slick.grid.css" type="text/css" media="screen" charset="utf-8" />
    <link rel="stylesheet" href="css/smoothness/jquery-ui-1.8.5.custom.css" type="text/css" media="screen" charset="utf-8" />
    <link rel="stylesheet" href="css/examples.css" type="text/css" media="screen" charset="utf-8" />
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script language="javascript" src="js/jquery.json.js"></script>

</head>
<body>
    <div id="content_cont">

        <div id="main">

                <div style="position:relative">
                    <div style="width:600px;">
                        <div id="myGrid" style="width:100%;height:500px;"></div>
                    </div>
                </div>  



            pricing

        </div><!-- #main -->

    </div><!-- #content_cont -->

        <script src="lib/firebugx.js"></script>


        <script src="lib/jquery-ui-1.8.5.custom.min.js"></script>
        <script src="lib/jquery.event.drag-2.0.min.js"></script>

        <script src="slick.core.js"></script>
        <script src="plugins/slick.cellrangeselector.js"></script>
        <script src="plugins/slick.cellselectionmodel.js"></script>
        <script src="slick.editors.js"></script>
        <script src="slick.grid.js"></script>


        <script type="text/javascript">
            var grid;
            var data = [];
            var columns = [
                {id:"title", name:"Title", field:"title", editor:TextCellEditor},
                {id:"duration", name:"Duration", field:"duration", editor:TextCellEditor},
                {id:"%", name:"% Complete", field:"percentComplete", editor:TextCellEditor},
                {id:"start", name:"Start", field:"start", editor:TextCellEditor},
                {id:"finish", name:"Finish", field:"finish", editor:TextCellEditor},
                {id:"effort-driven", name:"Effort Driven", field:"effortDriven", editor:TextCellEditor}
            ];

            var options = {
                    editable: true,
                    enableCellNavigation: true,
                    asyncEditorLoading: false,
                    autoEdit: true
                };

            $(function() {

                <?php echo $data ?>
                grid = new Slick.Grid($("#myGrid"), data, columns, options);

            })



        </script>

<form method="POST" action="save_price.php">
    <input type="submit" value="Save">
    <input type="hidden" name="data" value="">
</form>
<script type="text/javascript">
  $(function() {
    $("form").submit(
      function() {
        $("input[name='data']").val($.JSON.encode(data));

      }
    );
  });
</script>

</body>
</html>

更多相关文章

  1. 使用mysql验证在php中登录表单
  2. 在MySQL数据库中搜索与多个Tag记录相关/包含的书签
  3. 使用jquery和php手动在数据库中增加一个字段[复制]
  4. 如何在Laravel 5表单请求中使用请求路由参数?
  5. 如何使用ajax向php发送与每个按钮相关的数据?
  6. php标准库 SPL 数据结构之-----SplDoublyLinkedList(双向链表)
  7. 防止Ajax创建表单的默认值
  8. php 封装原生数据导出的方法
  9. 在PHP和MySQL中同时插入来自多个表单的多个值

随机推荐

  1. 算法 - 给出一个字符串str,输出包含两个
  2. JavaScript unshift()函数移入数据到数组
  3. 《JavaScript 高级程序设计》学习总结六(1
  4. OSGi 学习之路(4) - osgi的模块化 java在模
  5. POST json和图像到服务器android
  6. linux下安装zookeeper报错Syntax error:
  7. 3D相机缩放并遵循java中的物理特性?
  8. 为什么HttpUrlConnection在移动数据连接
  9. Thrift项目Server端开发流程
  10. Akka ZeroMQExtension使用一个zeromq套接