2011-12-02 1 views
1

내가 jQuery를 /있는 jqGrid 초보자이야와 MySQL을 DB에 /에서 삭제합니다. 내 그리드에 데이터를 추가/편집하는 edit/add 버튼도 있습니다. 그러나, 내가 어떻게 그 추가/편집 MySQL 데이터베이스를 업데이 트하는지 모르겠다. 어떤 제안? 여기추가/편집/내있는 jqGrid 선택하고 올바르게 내 데이터를 표시있어</p> <p>...있는 jqGrid

내 scripts.js는 파일입니다

여기
$("#table-maintenance-conflicts").jqGrid(
    { 
     url:'maintenanceConflicts.php', 
     editurl:'maintenanceConflicts-edit.php', 
     datatype: 'xml', 
     mtype: 'GET', 
     colNames:['Conflict Code', 'Description', 'Updated By', 'Updated On'], // Set column names of the grid 
     colModel :[ // Set the settings for each individual column of the grid 
      { 
       name:'conflictCode', 
       index:'conflictCode', 
       width:120, 
       align:'center', 
       editable:false, 
      }, 
      {name:'description', index:'description', width:200, editable:true, edittype:"text"}, 
      {name:'updatedBy', index:'updatedBy', width:120, editable:true, edittype:"text", editrules: {required: true}}, 
      {name:'updatedOn', index:'updatedOn', width:120, editable:false, editrules: {required: true}} 
     ], 
     pager: '#pager-maintenance-conflicts', 
     rowNum:10, // To start, the user will see 10 records on the first page 
     rowList:[10,15,20], // How many records is the user able to see per page? 
     sortname: 'conflictCode', 
     sortorder: 'desc', // Order the 'sortname' should be sorted in 
     viewrecords: true, // View the records upon grid startup? or wait until a search? 
     caption: 'Maintenance | Conflicts' // Title of the grid (at the top) 
    }).navGrid('#pager-maintenance-conflicts',{ 
     edit:true, 
     add:true, 
     view:true, 
     del:true, 
     search:true, 
     refresh:true 
    }); 

// ADD 
$("#add_table-maintenance-conflicts").click(function(){ 

    jQuery("#table-maintenance-conflicts").jqGrid('editGridRow',"new",{ 
     mtype: 'POST', 
     reloadAfterSubmit:false, 
     closeAfterAdd:true,   
    }); 

}); 

// EDIT 
$("#edit_table-maintenance-conflicts").click(function(){ 

    var gr = jQuery("#table-maintenance-conflicts").jqGrid('getGridParam','selrow'); 
    if(gr != null) 
     jQuery("#table-maintenance-conflicts").jqGrid('editGridRow',gr,{ 
      mtype: 'POST', 
      reloadAfterSubmit:false, 
      closeAfterEdit:true 
     }); 

}); 

// DELETE 
$("#del_table-maintenance-conflicts").click(function(){ 

    var gr = jQuery("#table-maintenance-conflicts").jqGrid('getGridParam','selrow'); 
    if(gr != null) 
     jQuery("#table-maintenance-conflicts").jqGrid('delGridRow',gr,{ 
      mtype: 'POST', 
      reloadAfterSubmit:false 
     }); 

}); 

내 maintenanceConflicts-edit.php 파일이 있습니다 :

<?php 

//include the information needed for the connection to MySQL data base server. 
// we store here username, database and password 
$dbhost = "localhost"; 

$dbuser = "root"; 

$dbpassword = ""; 

$database = "ftdbadmin"; 

// connect to the database 
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error()); 
//echo "Connected to MySQL <br />"; 

// select the database 
mysql_select_db($database) or die("Error conecting to db."); 
//echo "Connected to the selected database: ".$database."<br />"; 

// If we're ADDING 
if($_POST['oper']=='add') 
{ 

} 

// If we're EDITING 
if($_POST['oper']=='edit') 
{ 
    $conflictCode  = mysql_real_escape_string($_POST['conflictCode']); 
    $description = mysql_real_escape_string($_POST['description']); 
    $updatedBy = mysql_real_escape_string($_POST['updatedBy']); 
    // $updatedOn = mysql_real_escape_string($_GET['updatedOn']); 

$SQL = "UPDATE tblconflict SET updatedBy = '".$updatedBy."', description = '".$description."' WHERE conflictCode = ".$conflictCode; 

    echo $SQL; 
    $result=mysql_query($SQL) or die(mysql_error()); 

    mysql_close($db); 
} 

// If we're DELETING 
if($_POST['oper']=='del') 
{ 

} 

?> 

어떤 도움을 크게 감상 할 수있다!

+1

이 링크 확인 http://www.trirand.com/blog/?p=617 –

+0

감사합니다 Andrey, 블로그 게시물은 상업용 제품, PHP 용 jQGrid에 초점을 맞춘 것 같습니다 ... – FastTrack

+0

매우 이상합니다. 나 .. 나는 사방을 검색 해왔고, 그리드와 함께 Add/Edit/Delete 기능을 구현하는 방법에 대한 좋은 예는 찾을 수 없다 ... 누구든지 그들이 알고있는 예제 나 튜토리얼을 가지고 있는가? – FastTrack

답변

-2

나는 몇 달 전에 Wiki, Google 및이 사이트를 방문하여이 사실을 파악했습니다. 나는 jQGrid를위한이 PHP CRUD 템플릿을 우연히 발견했다. 조금 조정하면 모든 격자로 작업 할 수 있습니다. 일단 작업을 시작하게되면 개선과 확장을위한 여지가 많이 생깁니다. 올바른 방향으로 시작해야합니다.

+0

답변을 직접 제공하는 것을 고려하십시오. 그것은 그대로, 그것은 SO 표준을 만족하지 않는 링크 전용 대답 자격. – BartoszKP

+0

@BartoszKP 링크는 대답입니다. 왜 불필요하게 링크 내용을 복사/붙여 넣을까요? – FastTrack

+1

링크가 무효화 될 수 있으므로 불필요한 것은 아닙니다. 그리고 현재 SO 정책이 수립되어 있습니다. 예를 들어 [this] (http://meta.stackexchange.com/a/95691/231717)를 읽어 보시고, 정말로 관심이 있으시다면 이것에 대한 수많은 메타 토론을 읽어보십시오. 어느 쪽이든, 컨센서스는 링크 전용 답변을 환영하지 않는다는 것입니다. – BartoszKP