Forum
July 12th, 2025
A
A
A
Topic RSS
Related Topics
Offline
The forums are currently locked and only available for read only access
Topic RSS
Related Topics
how to save the result to database after inline edit?
24/08/2011
23:00
23:00
jitangc
New Member
Members
Forum Posts: 1
Member Since:
24/08/2011
24/08/2011
OfflineFirst thanks this great plugin. I'm new to use jqgrid and there is a problem when i try to update the change into database after the row has been edited. Here is my code:
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var lastsel2
$("#list").jqGrid({
url:'example.php',
datatype: 'xml',
mtype: 'GET',
colNames:['id','name', 'status'],
colModel :[
{name:'id', index:'id', width:55},
{name:'name', index:'name', width:90, editable: true},
{name:'status', index:'status', width:80, align:'right', editable: true}
],
onSelectRow: function(id){
if(appid && id!==lastsel2){
jQuery('#list').restoreRow(lastsel2);
jQuery('#list').editRow(id,true);
lastsel2=id;
}
},
editurl: "example.php",
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'appid',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'My first grid'
});
});
</script>
</head>
<body>
<table id="list"><tr><td/></tr></table>
<div id="pager"></div>
</body>And here is the php code:
<?php
include("dbconfig.php");
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
if (!$sidx)
$sidx = 1;
$db = mysql_connect("$dbhost", "$dbuser", "$dbpassword") or die("Connection Error: " . mysql_error());
mysql_select_db("$database") or die("Error connecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM app");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$count = $row['count'];
if ($count > 0 && $limit > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page = $total_pages;
$start = $limit * $page - $limit;
if ($start < 0)
$start = 0;
$SQL = "SELECT id, name, status FROM app";
$result = mysql_query($SQL) or die("Couldn't execute query." . mysql_error());
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";
// be sure to put text data in CDATA
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$s .= "<row id='" . $row['id'] . "'>";
$s .= "<cell>" . $row['id'] . "</cell>";
$s .= "<cell>" . $row['name'] . "</cell>";
$s .= "<cell>" . $row['status'] . "</cell>";
$s .= "</row>";
}
$s .= "</rows>";
echo $s;
?>It's able to display the data from mysql table, and also can make inline edit. But the change can't
be updated into the database. I don't know how to implement it. I guess it need a variable to store
the value of the edited row, and use a sql to update it. But I'm not sure about it, anyone could help?
Thanks!
Forum Timezone: Europe/Sofia
Most Users Ever Online: 994
Currently Online:
27 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66
Log In
Home