<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: how to save the result to database after inline edit?</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-save-the-result-to-database-after-inline-edit</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/how-to-save-the-result-to-database-after-inline-edit/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>jitangc on how to save the result to database after inline edit?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-to-save-the-result-to-database-after-inline-edit#p24403</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-to-save-the-result-to-database-after-inline-edit#p24403</guid>
        	        	<description><![CDATA[<p>First thanks this great plugin. I&#39;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:</p>
<pre class="lang-php prettyprint"><span style="font-family: monospace;"><p><input type='button' class='sfcodeselect' name='sfselectit2488' value='Select Code' data-codeid='sfcode2488' /></p><div class='sfcode' id='sfcode2488'>&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; media=&#34;screen&#34; href=&#34;css/ui-lightness/jquery-ui-1.8.16.custom.css&#34; /&#62;<br />&#160; &#160; &#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; media=&#34;screen&#34; href=&#34;css/ui.jqgrid.css&#34; /&#62;<br /><br />&#160; &#160; &#60;style type=&#34;text/css&#34;&#62;<br />&#160; &#160; &#160; &#160; html, body {<br />&#160; &#160; &#160; &#160; &#160; &#160; margin: 0;<br />&#160; &#160; &#160; &#160; &#160; &#160; padding: 0;<br />&#160; &#160; &#160; &#160; &#160; &#160; font-size: 75%;<br />&#160; &#160; &#160; &#160; }<br />&#160; &#160; &#60;/style&#62;<br /><br />&#160; &#160; &#60;script src=&#34;js/jquery-1.5.2.min.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;<br />&#160; &#160; &#60;script src=&#34;js/i18n/grid.locale-en.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;<br />&#160; &#160; &#60;script src=&#34;js/jquery.jqGrid.min.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;<br /><br />&#160; &#160; &#60;script type=&#34;text/javascript&#34;&#62;<br /><br />&#160; &#160; &#160; &#160; $(function(){ <br />&#160; &#160; &#160; &#160; &#160; &#160; var lastsel2<br />&#160; &#160; &#160; &#160; &#160; &#160; $(&#34;#list&#34;).jqGrid({ &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; url:&#39;example.php&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; datatype: &#39;xml&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; mtype: &#39;GET&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; colNames:[&#39;id&#39;,&#39;name&#39;, &#39;status&#39;],<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; colModel :[ <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {name:&#39;id&#39;, index:&#39;id&#39;, width:55}, <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {name:&#39;name&#39;, index:&#39;name&#39;, width:90, editable: true}, <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {name:&#39;status&#39;, index:&#39;status&#39;, width:80, align:&#39;right&#39;, editable: true} &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ], &#160; &#160;<br /><br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; onSelectRow: function(id){<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(appid &#38;&#38; id!==lastsel2){<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; jQuery(&#39;#list&#39;).restoreRow(lastsel2);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; jQuery(&#39;#list&#39;).editRow(id,true);<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lastsel2=id;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; },<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; editurl: &#34;example.php&#34;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; pager: &#39;#pager&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; rowNum:10,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; rowList:[10,20,30],<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; sortname: &#39;appid&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; sortorder: &#39;desc&#39;,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; viewrecords: true,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; gridview: true,<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; caption: &#39;My first grid&#39;<br />&#160; &#160; &#160; &#160; &#160; &#160; }); <br />&#160; &#160; &#160; &#160; });<br /><br />&#160; &#160; &#60;/script&#62;<br /><br />&#60;/head&#62;<br />&#60;body&#62;<br />&#160; &#160; &#60;table id=&#34;list&#34;&#62;&#60;tr&#62;&#60;td/&#62;&#60;/tr&#62;&#60;/table&#62; <br />&#160; &#160; &#60;div id=&#34;pager&#34;&#62;&#60;/div&#62; <br />&#60;/body&#62;</div>And here is the php code:</span></pre>
<pre class="lang-php prettyprint"></pre>
<pre class="lang-php prettyprint"><span style="font-family: monospace;"><p><input type='button' class='sfcodeselect' name='sfselectit2011' value='Select Code' data-codeid='sfcode2011' /></p><div class='sfcode' id='sfcode2011'>&#60;?php<br />include(&#34;dbconfig.php&#34;);<br />$page = $_GET[&#39;page&#39;];<br />$limit = $_GET[&#39;rows&#39;];<br />$sidx = $_GET[&#39;sidx&#39;];<br />$sord = $_GET[&#39;sord&#39;];<br /><br />if (!$sidx)<br />&#160; &#160; $sidx = 1;<br /><br />$db = mysql_connect(&#34;$dbhost&#34;, &#34;$dbuser&#34;, &#34;$dbpassword&#34;) or die(&#34;Connection Error: &#34; . mysql_error());<br /><br />mysql_select_db(&#34;$database&#34;) or die(&#34;Error connecting to db.&#34;);<br /><br />$result = mysql_query(&#34;SELECT COUNT(*) AS count FROM app&#34;);<br />$row = mysql_fetch_array($result, MYSQL_ASSOC);<br />$count = $row[&#39;count&#39;];<br /><br />if ($count &#62; 0 &#38;&#38; $limit &#62; 0) {<br />&#160; &#160; $total_pages = ceil($count / $limit);<br />} else {<br />&#160; &#160; $total_pages = 0;<br />}<br /><br />if ($page &#62; $total_pages)<br />&#160; &#160; $page = $total_pages;<br /><br />$start = $limit * $page - $limit;<br /><br />if ($start &#60; 0)<br />&#160; &#160; $start = 0;<br /><br />$SQL = &#34;SELECT id, name, status FROM app&#34;;<br />$result = mysql_query($SQL) or die(&#34;Couldn&#39;t execute query.&#34; . mysql_error());<br /><br />header(&#34;Content-type: text/xml;charset=utf-8&#34;);<br /><br />$s = &#34;&#60;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&#62;&#34;;<br />$s .= &#34;&#60;rows&#62;&#34;;<br />$s .= &#34;&#60;page&#62;&#34; . $page . &#34;&#60;/page&#62;&#34;;<br />$s .= &#34;&#60;total&#62;&#34; . $total_pages . &#34;&#60;/total&#62;&#34;;<br />$s .= &#34;&#60;records&#62;&#34; . $count . &#34;&#60;/records&#62;&#34;;<br /><br />// be sure to put text data in CDATA<br />while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {<br />&#160; &#160; $s .= &#34;&#60;row id=&#39;&#34; . $row[&#39;id&#39;] . &#34;&#39;&#62;&#34;;<br />&#160; &#160; $s .= &#34;&#60;cell&#62;&#34; . $row[&#39;id&#39;] . &#34;&#60;/cell&#62;&#34;;<br />&#160; &#160; $s .= &#34;&#60;cell&#62;&#34; . $row[&#39;name&#39;] . &#34;&#60;/cell&#62;&#34;;<br />&#160; &#160; $s .= &#34;&#60;cell&#62;&#34; . $row[&#39;status&#39;] . &#34;&#60;/cell&#62;&#34;;<br />&#160; &#160; $s .= &#34;&#60;/row&#62;&#34;;<br />}<br />$s .= &#34;&#60;/rows&#62;&#34;;<br />echo $s;<br />?&#62;</div>It&#39;s able to display the data from mysql table, and also can make inline edit. But the change can&#39;t</span></pre>
<pre class="lang-php prettyprint"><span style="font-family: monospace;"> be updated into the database. I don&#39;t know how to implement it. I guess it need a variable to store</span></pre>
<pre class="lang-php prettyprint"><span style="font-family: monospace;">the value of the edited row, and use a sql to update it. But I&#39;m not sure about it, anyone could help?</span></pre>
<pre class="lang-php prettyprint"><span style="font-family: monospace;">Thanks!</span></pre>
]]></description>
        	        	<pubDate>Wed, 24 Aug 2011 23:00:15 +0300</pubDate>
        </item>
</channel>
</rss>