<?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: Help with Inline Edit -Record won't update</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/help-with-inline-edit-record-wont-update</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/help-with-inline-edit-record-wont-update/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>soper on Help with Inline Edit -Record won't update</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/help-with-inline-edit-record-wont-update#p22055</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/help-with-inline-edit-record-wont-update#p22055</guid>
        	        	<description><![CDATA[</p>
<p>something in the code is missing and i can&#39;t figure out what..maybe you guys will be able to help..</p>
<p>records simply won&#39;t update.</p>
</p>
<p>here is the JS:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1047' value='Select Code' data-codeid='sfcode1047' /></p>
<div class='sfcode' id='sfcode1047'>&#60;table id=&#34;list&#34; class=&#34;scroll&#34; cellpadding=&#34;0&#34; cellspacing=&#34;0&#34;&#62;&#60;/table&#62; <br />&#60;div id=&#34;pager&#34; class=&#34;scroll&#34; style=&#34;text-align:center;&#34;&#62;&#60;/div&#62; <br />&#160;&#60;script type=&#34;text/javascript&#34;&#62;<br />var lastSelectedId;<br />var theme = &#34;steel&#34;;</p>
<p>$(&#34;head&#34;).append(&#34;&#60;link&#62;&#34;);<br />css = $(&#34;head&#34;).children(&#34;:last&#34;);<br />css.attr({<br />&#160;&#160; rel:&#160; &#34;stylesheet&#34;,<br />&#160;&#160; type: &#34;text/css&#34;,<br />&#160;&#160; href: &#34;scripts/themes/&#34;+theme+&#34;/grid.css&#34;,<br />&#160;&#160; title: theme,<br />&#160;&#160; media: &#34;screen&#34;<br />});</p>
<p>$(&#39;#list&#39;).jqGrid({<br />&#160;&#160;&#160;&#160; url:&#39;grid.php&#39;,<br />&#160; datatype: &#39;json&#39;,<br />&#160; mtype: &#39;POST&#39;,<br />&#160;&#160;&#160;&#160; colNames:[&#39;ID&#39;,&#39;Race_Name&#39;, &#39;Race_Year&#39;, &#39;Race_Result&#39;],<br />&#160;&#160;&#160;&#160; colModel:[&#160;&#160; &#160;<br />&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;ID&#39;,index:&#39;ID&#39;, width:55,editable:false},&#160;&#160;&#160; &#160;<br />&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;Race_Name&#39;,index:&#39;Race_Name&#39;, width:100,editable:true, edittype:&#39;text&#39;,editoptions:{size:30,maxlength:50}},<br />&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;Race_Year&#39;,index:&#39;Race_Year&#39;, width:80, editable:true, edittype:&#39;text&#39;,editoptions:{size:30,maxlength:50}},<br />&#160;&#160;&#160;&#160;&#160;&#160; {name:&#39;Race_Result&#39;,index:&#39;Race_Result&#39;, width:80, editable:true, edittype:&#39;text&#39;,editoptions:{size:30,maxlength:50}} &#160;<br />&#160;&#160;&#160;&#160; ],<br />&#160;&#160;&#160;&#160; rowNum:10,<br />&#160;&#160;&#160;&#160; rowList:[5,10,20,30],<br />&#160;&#160;&#160;&#160; imgpath: &#39;scripts/themes/&#39;+theme+&#39;/images&#39;,//alters buttons<br />&#160;&#160;&#160;&#160; pager: $(&#39;#pager&#39;),<br />&#160;&#160;&#160;&#160; sortname: &#39;ID&#39;,<br />&#160;&#160;&#160; viewrecords: true,<br />&#160;&#160;&#160; sortorder: &#34;desc&#34;,<br />&#160;&#160;&#160; caption:&#34;JSON Example&#34;,<br />&#160; width:600,<br />&#160; height:250, &#160;<br />&#160; onSelectRow: function(id){<br />&#160;&#160;&#160; if(id &#38;&#38; id!==lastSelectedId){<br />&#160;&#160;&#160;&#160;&#160; $(&#39;#list&#39;).restoreRow(lastSelectedId);<br />&#160;&#160;&#160;&#160;&#160; $(&#39;#list&#39;).editRow(id,true,null,onSaveSuccess);<br />&#160;&#160;&#160;&#160;&#160; lastSelectedId=id;<br />&#160;&#160;&#160; }<br />&#160; },<br />&#160; editurl:&#39;grid.php?action=save&#39;<br />});<br />function onSaveSuccess(xhr)<br />{<br />&#160; response = xhr.responseText;<br />&#160; if(response == 1)<br />&#160;&#160;&#160; return true;<br />&#160; return false;<br />}<br />&#60;/script&#62;</p>
</div>
<p>next is grid.php:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4697' value='Select Code' data-codeid='sfcode4697' /></p>
<div class='sfcode' id='sfcode4697'>&#60;?php<br />// load error handling script and the Grid class<br />require_once(&#39;error_handler.php&#39;);<br />require_once(&#39;grid.class.php&#39;);<br />$action = &#39;load&#39;;<br />if(isset($_GET[&#39;action&#39;]))&#160;&#160; &#160;<br />&#160;&#160; &#160;$action = $_GET[&#39;action&#39;];<br />if($action == &#39;load&#39;)<br />{<br />&#160;&#160; &#160;$page = $_POST[&#39;page&#39;]; <br />&#160;&#160; &#160;$limit = $_POST[&#39;rows&#39;]; <br />&#160;&#160; &#160;$sidx = $_POST[&#39;sidx&#39;]; <br />&#160;&#160; &#160;$sord = $_POST[&#39;sord&#39;]; <br />&#160;&#160; &#160;$grid = new Grid($page,$limit,$sidx,$sord);<br />&#160;&#160; &#160;$response-&#62;page = $page;<br />&#160;&#160; &#160;$response-&#62;total = $grid-&#62;getTotalPages();<br />&#160;&#160; &#160;$response-&#62;records = $grid-&#62;getTotalItemsCount();<br />&#160;&#160; &#160;$currentPageItems = $grid-&#62;getCurrentPageItems();</p>
<p>&#160;&#160; &#160;for($i=0;$i&#60;count($currentPageItems);$i++) {<br />&#160;&#160; &#160;&#160;&#160; &#160;$response-&#62;rows[$i][&#39;id&#39;]=$currentPageItems[$i][&#39;ID&#39;];<br />&#160;&#160; &#160;&#160;&#160; &#160;$response-&#62;rows[$i][&#39;cell&#39;]=array(<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$currentPageItems[$i][&#39;ID&#39;],<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$currentPageItems[$i][&#39;Race_Name&#39;],<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$currentPageItems[$i][&#39;Race_Year&#39;],<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$currentPageItems[$i][&#39;Race_Result&#39;]<br />&#160;&#160; &#160;&#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;} <br />&#160;&#160; &#160;echo json_encode($response);<br />}<br />elseif ($action == &#39;save&#39;)<br />{<br />&#160;&#160; &#160;$ID = $_POST[&#39;id&#39;];<br />&#160;&#160; &#160;$Race_Name = $_POST[&#39;Race_Name&#39;];<br />&#160;&#160; &#160;$Race_Year = $_POST[&#39;Race_Year&#39;];<br />&#160;&#160; &#160;$Race_Result = $_POST[&#39;Race_Result&#39;];<br />&#160;&#160; &#160;$grid = new Grid();<br />&#160;&#160; &#160;echo $grid-&#62;updateItem($ID,$Race_Result,$Race_Year,$Race_Name);<br />}<br />?&#62;</p>
</div>
<p>and grid.class.php:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit838' value='Select Code' data-codeid='sfcode838' /></p>
<div class='sfcode' id='sfcode838'>&#60;?php<br />// load configuration file<br />require_once(&#39;config.php&#39;);<br />// start session<br />session_start();</p>
<p>// includes functionality to manipulate the products list <br />class Grid <br />{&#160;&#160;&#160;&#160; &#160;<br />&#160; // grid pages count<br />&#160; private $mTotalPages;<br />&#160; // grid items count<br />&#160; private $mTotalItemsCount;<br />&#160; private $mItemsPerPage;<br />&#160; private $mCurrentPage;<br />&#160; <br />&#160; private $mSortColumn;<br />&#160; private $mSortDirection;<br />&#160; // database handler<br />&#160; private $mMysqli;<br />&#160;&#160; &#160;<br />&#160; // class constructor &#160;<br />&#160; function __construct( $currentPage =1, $itemsPerPage=5, $sortColumn=&#39;ID&#39;, $sortDirection=&#39;asc&#39;) <br />&#160; {&#160; &#160;<br />&#160;&#160;&#160; // create the MySQL connection<br />&#160;&#160;&#160; $this-&#62;mMysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DB_DATABASE);<br />&#160;&#160;&#160; $this-&#62;mCurrentPage = $currentPage;<br />&#160;&#160; &#160;$this-&#62;mItemsPerPage = $itemsPerPage;<br />&#160;&#160; &#160;$this-&#62;mSortColumn = $sortColumn;<br />&#160;&#160; &#160;$this-&#62;mSortDirection = $sortDirection;<br />&#160;&#160; &#160;// call countAllRecords to get the number of grid records<br />&#160;&#160;&#160; $this-&#62;mTotalItemsCount = $this-&#62;countAllItems();<br />&#160;&#160; &#160;if($this-&#62;mTotalItemsCount &#62;0)&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;$this-&#62;mTotalPages = ceil($this-&#62;mTotalItemsCount/$this-&#62;mItemsPerPage);<br />&#160;&#160; &#160;else<br />&#160;&#160; &#160;&#160;&#160; &#160;$this-&#62;mTotalPages=0;&#160;&#160; &#160;<br />&#160;&#160; &#160;if($this-&#62;mCurrentPage &#62; $this-&#62;mTotalPages)<br />&#160;&#160; &#160;&#160;&#160; &#160;$this-&#62;mCurrentPage = $this-&#62;mTotalPages;<br />&#160; }<br />&#160; <br />&#160; <br />&#160; <br />&#160; // read a page of products and save it to $this-&#62;grid<br />&#160; public function getCurrentPageItems()<br />&#160; {<br />&#160;&#160;&#160; // create the SQL query that returns a page of products<br />&#160;&#160;&#160; $queryString = &#39;SELECT * FROM userCake_races&#39;;&#160;&#160; &#160;<br />&#160;&#160; &#160;$queryString .= &#39; ORDER BY &#39;.$this-&#62;mMysqli-&#62;real_escape_string($this-&#62;mSortColumn).&#39; &#39;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;.$this-&#62;mMysqli-&#62;real_escape_string($this-&#62;mSortDirection);&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;$start = $this-&#62;mItemsPerPage* $this-&#62;mCurrentPage - $this-&#62;mItemsPerPage; // do not put $limit*($page - 1)<br />&#160;&#160;&#160; if ($start&#60;0) <br />&#160;&#160; &#160;&#160;&#160; &#160;$start = 0;<br />&#160;&#160; &#160;$queryString .= &#39; LIMIT &#39;.$start.&#39;,&#39;.$this-&#62;mItemsPerPage;<br />&#160;&#160; &#160;<br />&#160;&#160;&#160; // execute the query<br />&#160;&#160;&#160; if ($result = $this-&#62;mMysqli-&#62;query($queryString)) <br />&#160;&#160;&#160; {<br />&#160;&#160; &#160;&#160; for($i = 0; $items[$i] = $result-&#62;fetch_assoc(); $i++) ;&#160; &#160;</p>
<p>&#160;&#160; &#160;&#160; // Delete last empty one<br />&#160;&#160; &#160;&#160; array_pop($items);<br />&#160;&#160; &#160; &#160;<br />&#160;&#160;&#160;&#160;&#160; // close the results stream&#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; $result-&#62;close();<br />&#160;&#160; &#160;&#160; return $items;<br />&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160; }<br />&#160; <br />&#160; public function getTotalPages()<br />&#160; {<br />&#160;&#160; &#160;return $this-&#62;mTotalPages;<br />&#160; }<br />&#160; <br />&#160; <br />&#160; // update a product<br />&#160; public function updateItem($ID, $Race_Name, $Race_Year, $Race_Result)<br />&#160; {<br />&#160;&#160;&#160; // escape input data for safely using it in SQL statements<br />&#160;&#160;&#160; $ID = $this-&#62;mMysqli-&#62;real_escape_string($ID);<br />&#160;&#160;&#160; $Race_Name = $this-&#62;mMysqli-&#62;real_escape_string($Race_Name);<br />&#160;&#160;&#160; $Race_Year = $this-&#62;mMysqli-&#62;real_escape_string($Race_Year);<br />&#160;&#160;&#160; $Race_Result = $this-&#62;mMysqli-&#62;real_escape_string($Race_Result);<br />&#160;&#160;&#160; // build the SQL query that updates a product record<br />&#160;&#160;&#160; $queryString =&#160; &#39;UPDATE userCake_races SET Race_Name=&#34;&#39; . $Race_Name . &#39;&#34;, &#39; . <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#39;Race_Year=&#39; . $Race_Year . &#39;,&#39; . <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#39;Race_Result=&#39; . $Race_Result . <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#39; WHERE ID=&#39; . $ID;&#160;&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;<br />&#160;&#160;&#160; // execute the SQL command&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160;&#160; $this-&#62;mMysqli-&#62;query($queryString); &#160;<br />&#160;&#160; &#160;return $this-&#62;mMysqli-&#62;affected_rows;<br />&#160; }</p>
<p>&#160; </p>
<p>&#160; // returns the total number of records for the grid<br />&#160; private function countAllItems()<br />&#160; {<br />&#160;&#160;&#160;&#160;&#160; // the query that returns the record count<br />&#160;&#160;&#160;&#160;&#160; $count_query = &#39;SELECT COUNT(*) FROM userCake_races&#39;;<br />&#160;&#160;&#160;&#160;&#160; // execute the query and fetch the result <br />&#160;&#160;&#160;&#160;&#160; if ($result = $this-&#62;mMysqli-&#62;query($count_query)) <br />&#160;&#160;&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // retrieve the first returned row<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $row = $result-&#62;fetch_row(); &#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // close the database handle<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $result-&#62;close();<br />&#160;&#160; &#160;&#160;&#160; &#160;return $row[0];<br />&#160;&#160;&#160;&#160;&#160; }&#160;&#160; &#160;<br />&#160;&#160; &#160;return 0;<br />&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160; <br />&#160; public function getTotalItemsCount()<br />&#160; {<br />&#160;&#160; &#160;return $this-&#62;mTotalItemsCount;<br />&#160; }<br />&#160;&#160; &#160;<br />// end class Grid<br />} <br />?&#62;</p>
</div>
]]></description>
        	        	<pubDate>Sat, 12 Feb 2011 01:43:29 +0200</pubDate>
        </item>
</channel>
</rss>