<?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: add/edit/del . How write to database?</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/addeditdel-how-write-to-database</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/addeditdel-how-write-to-database/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>rappi on add/edit/del . How write to database?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/addeditdel-how-write-to-database#p31432</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/addeditdel-how-write-to-database#p31432</guid>
        	        	<description><![CDATA[<p>Ok. I have found the error!</p>
<p>It was a syntax error in my MySQL statement.</p>
<p>Rappi</p>
]]></description>
        	        	<pubDate>Sun, 07 Dec 2014 20:17:16 +0200</pubDate>
        </item>
        <item>
        	<title>rappi on add/edit/del . How write to database?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/addeditdel-how-write-to-database#p31424</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/addeditdel-how-write-to-database#p31424</guid>
        	        	<description><![CDATA[<p>Hello.</p>
<p>I am new with jqgrid and I don't know how it works. I am a PHP/MySQL/Html programmer........</p>
<p>My Problem is, how can I write the data to a MySQL Database?</p>
<p>I read the data from database and the grid show it, but when I click add/edit/del nothing is saved.</p>
<p>My mainfile:</p>
<blockquote>
<p>
&#60;?php</p>
<p>require_once("models/config.php");<br />
 include("template/header.php"); </p>
<p> ?&#62;<br />
&#60;script type="text/javascript"&#62;<br />
$(function () {<br />
 $("#list").jqGrid({<br />
 url: "adm_land_action.php",<br />
 datatype: "xml",<br />
 mtype: "POST",<br />
 colNames: ["id", "Aufenthaltsort"],<br />
 colModel: [<br />
 { name: "id", width: 50, search:false, editable: false },<br />
 { name: "land", width: 800, editable: true, search:true, editoptions:{size:25}, edittype:"text", sorttype:'string', searchoptions:{sopt:['cn','eq','bw','ew']}}<br />
 ],<br />
 pager: "#pager",<br />
 rowNum: 10,<br />
 //rowList: [10, 20, 30],<br />
 sortname: "land",<br />
 sortorder: "asc",<br />
 loadonce:false,<br />
 viewrecords: true,<br />
 gridview: true,<br />
 autoencode: true,<br />
 editurl: "adm_land_edit.php",<br />
 caption: "Aufenthaltsorte"<br />
 })<br />
 jQuery("#list").jqGrid('filterToolbar',{searchOperators : true});</p>
<p> jQuery("#list").jqGrid('navGrid','#pager',<br />
 {search:false,edit:true,add:true,del:true}, //options<br />
 {height:280,reloadAfterSubmit:true}, // edit options<br />
 {height:280,reloadAfterSubmit:true}, // add options<br />
 {reloadAfterSubmit:true}, // del options<br />
 {} // search options<br />
 );</p>
<p> $("#add").click(function(){<br />
 jQuery("#list").jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:true})});</p>
<p> $("#edit").click(function(){<br />
 jQuery("#list").jqGrid('editGridRow',"edit",{height:280,reloadAfterSubmit:true})});</p>
<p> $("#del").click(function(){<br />
 jQuery("#list").jqGrid('editGridRow',"del",{height:280,reloadAfterSubmit:true})});<br />
});<br />
&#60;/script&#62;</p>
<p>&#60;div class="container"&#62;<br />
 &#60;header&#62;<br />
 &#60;?php include("template/sub_header.php"); ?&#62;<br />
 &#60;/header&#62;<br />
 &#60;h1&#62;Aufenthaltsorte&#60;/h1&#62;<br />
 &#60;?php if(isUserLoggedIn()) {<br />
 include('template/tm_menu.php');<br />
 } else {<br />
 echo "&#60;meta http-equiv='refresh' content='0; URL=index.php'&#62;";<br />
 exit;<br />
 }<br />
 ?&#62;<br />
 &#60;article class="content"&#62;</p>
<p>&#60;?php if(isUserLoggedIn()) {<br />
 echo "</p>
<p>&#60;table id='list'&#62;&#60;/table&#62;<br />
 &#60;div id='pager'&#62;&#60;/div&#62;<br />
";</p>
<p> } ?&#62;<br />
 &#60;/article&#62;</p>
<p> &#60;?php include("template/footer.php"); ?&#62;Â </p>
</blockquote>
<p>My file to read the database adm_land_action.php</p>
<blockquote>
<p>
&#60;?php<br />
//include the information needed for the connection to MySQL data base server.<br />
// we store here username, database and password<br />
require_once("models/config.php");</p>
<p>// to the url parameter are added 4 parameters as described in colModel<br />
// we should get these parameters to construct the needed query<br />
// Since we specify in the options of the grid that we will use a GET method<br />
// we should use the appropriate command to obtain the parameters.<br />
// In our case this is $_GET. If we specify that we want to use post<br />
// we should use $_POST. Maybe the better way is to use $_REQUEST, which<br />
// contain both the GET and POST variables. For more information refer to php documentation.<br />
// Get the requested page. By default grid sets this to 1.<br />
$page = $_POST['page'];</p>
<p>// get how many rows we want to have into the grid - rowNum parameter in the grid<br />
$limit = $_POST['rows'];</p>
<p>// get index row - i.e. user click to sort. At first time sortname parameter -<br />
// after that the index from colModel<br />
$sidx = $_POST['sidx']; </p>
<p>// sorting order - at first time sortorder<br />
$sord = $_POST['sord']; </p>
<p>// if we not pass at first time index use the first column for the index or what you want<br />
if(!$sidx) $sidx =1; </p>
<p>// connect to the MySQL database server<br />
$db = mysql_connect($db_host, $db_user, $db_pass) or die("Connection Error: " . mysql_error());</p>
<p>// select the database<br />
mysql_select_db($db_name) or die("Error connecting to db."); </p>
<p>// calculate the number of rows for the query. We need this for paging the result<br />
$result = mysql_query("SELECT COUNT(*) AS count FROM ".$db_prefix."land");<br />
$row = mysql_fetch_array($result,MYSQL_ASSOC);<br />
$count = $row['count'];</p>
<p>// calculate the total pages for the query<br />
if( $count &#62; 0 &#38;&#38; $limit &#62; 0) {<br />
 $total_pages = ceil($count/$limit);<br />
} else {<br />
 $total_pages = 0;<br />
} </p>
<p>// if for some reasons the requested page is greater than the total<br />
// set the requested page to total page<br />
if ($page &#62; $total_pages) $page=$total_pages;</p>
<p>// calculate the starting position of the rows<br />
$start = $limit*$page - $limit;</p>
<p>// if for some reasons start position is negative set it to 0<br />
// typical case is that the user type 0 for the requested page<br />
if($start &#60;0) $start = 0; </p>
<p>// the actual query for the grid data<br />
$SQL = "SELECT id, land FROM ".$db_prefix."land ORDER BY $sidx $sord LIMIT $start , $limit";<br />
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error()); </p>
<p>// we should set the appropriate header information. Do not forget this.<br />
header("Content-type: text/xml;charset=utf-8");</p>
<p>$s = "&#60;?xml version='1.0' encoding='utf-8'?&#62;";<br />
$s .= "&#60;rows&#62;";<br />
$s .= "&#60;page&#62;".$page."&#60;/page&#62;";<br />
$s .= "&#60;total&#62;".$total_pages."&#60;/total&#62;";<br />
$s .= "&#60;records&#62;".$count."&#60;/records&#62;";</p>
<p>// be sure to put text data in CDATA<br />
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br />
 $s .= "&#60;row id='". $row['id']."'&#62;";<br />
 $s .= "&#60;cell&#62;". $row['id']."&#60;/cell&#62;";<br />
 $s .= "&#60;cell&#62;". $row['land']."&#60;/cell&#62;";<br />
 $s .= "&#60;/row&#62;";<br />
}<br />
$s .= "&#60;/rows&#62;"; </p>
<p>echo $s;<br />
?&#62;</p>
</blockquote>
<p>And my file to write to database adm_land_adit.php</p>
<blockquote>
<p>
&#60;?php<br />
//include the information needed for the connection to MySQL data base server.<br />
// we store here username, database and password<br />
require_once("models/config.php");</p>
<p>$id = $_POST['id'];Â </p>
<p>$land = $_POST['land'];</p>
<p>// connect to the MySQL database server<br />
$db = mysql_connect($db_host, $db_user, $db_pass) or die("Connection Error: " . mysql_error());</p>
<p>// select the database<br />
mysql_select_db($db_name) or die("Error connecting to db."); </p>
<p>// the actual query for the grid data<br />
$SQL = "update ".$db_prefix."land set land=$land where id=$id";<br />
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error()); </p>
<p>?&#62;</p>
</blockquote>
<p>It have only the edit function in it.</p>
<p>When I click on edit, the editform pop up and when I edit the entry and click on Save, the grid reloads, the form is showing again and the data is not changed.</p>
<p>What is wrong?</p>
<p>Have I don't understand the script and the functions?</p>
<p>Please help a newbie  <img src="http://www.trirand.com/blog/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="spWPSmiley" style="max-height:1em;margin:0"  /> </p>
<p>Greetz Rappi</p>
]]></description>
        	        	<pubDate>Thu, 04 Dec 2014 17:18:46 +0200</pubDate>
        </item>
</channel>
</rss>