gpt4 book ai didi

php - 使用 php 在 SlickGrid 中保存更改

转载 作者:可可西里 更新时间:2023-11-01 08:07:50 25 4
gpt4 key购买 nike

我设置了一个 SlickGrid,它正在使用 PHP 从我的数据库中读取数据,当我尝试将数据保存回我的数据库时出现了我的问题,我正在尝试使用 JSON 给我一个数组,我可以然后用于写回数据库,我看到这个线程对此进行了解释:

Saving changes in SlickGrid

所以我的代码中有隐藏的表单元素,并使用 JSON 对数据变量进行编码,将其分配给表单上隐藏的数据输入,此表单发布到名为 save_price.php 的页面,问题是当我 print_r 或 var_dump 数据变量时,我得到 null 作为输出,我认为这可能与我如何使用 PHP 将内容添加到数据变量有关,或者我正在做一些非常明显错误的事情,希望您能看到问题所在,网上没有大量关于使用 PHP 检索/保存到数据库的文档,所以我有点被困在墙上,这是我的代码:

最佳答案

好的,所以我发现了问题,以防万一有人正在努力让这一切正常工作,这是工作代码,它从数据库获取数据,然后将更改的数据发送到另一个页面进行处理,它需要一点一些改进,这将在我全部实现后发生:

<?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>

关于php - 使用 php 在 SlickGrid 中保存更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6573277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com