2011-02-19 4 views
0

Voici mon code. Ma recherche ne fonctionne pas et Edit montre mais ne pas enregistrer dans la base de données! J'ai essayé ce qui est dans cette URL, http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3asinge_searching. Mais je ne pouvais pas le corriger. Comment puis-je résoudre ce problème?La recherche jqGrid ne fonctionne pas

<SCRIPT type="text/javascript"> 
    $(function(){ 
     jQuery("#list1").jqGrid({ 
      url:'school_manager_db.php?q=1', 
      datatype: "xml", 
      colNames:['ID','Name', 'City', 'Email','Tel NO','Type','Notes'], 
      colModel:[ 
       {name:'id',index:'school_id', width:65,}, 
       {name:'name',index:'school_name', width:290,editable: true}, 
       {name:'city',index:'city', width:130,editable: true}, 
       {name:'email',index:'email', width:130,editable: true, align:"right"}, 
       {name:'tel',index:'contact', width:130,editable: true, align:"right"}, 
       {name:'type',index:'type', width:80,editable: true,edittype: 'select', 
       align:"right"}, 
       {name:'note',index:'note', width:150,editable: true, sortable:false} 
      ], 
      height:480, 
      rowNum:10, 
      rowList:[40,80,120], 
      imgpath: '/images', 
      pager: jQuery('#pager1'), 
      sortname: 'id', 
      viewrecords: true, 
      sortorder: "desc", 
      caption:'', 
      editurl:"someurl.php" 
     }).navGrid('#pager1',{ 
      edit:true, 
      add:true, 
      del:true 
     }); 
     jQuery("#list1").searchGrid(options); 
    }); 
</SCRIPT> 

Ma page PHP,

<?php 
    include("db.php"); 
    $page = $_GET['page']; // Get the requested page. 
    $limit = $_GET['rows']; // Get how many rows we want to have into the grid. 
    $sidx = $_GET['sidx']; // Get index row - i.e. user click to sort. 
    $sord = $_GET['sord']; // Get the direction. 

    if (!$sidx) 
     $sidx =1; 

    $result = mysql_query("SELECT COUNT(*) AS count FROM school"); 
    $row = mysql_fetch_array($result,MYSQL_ASSOC); 
    $count = $row['count']; 

    if($count >0) 
    { 
     $total_pages = ceil($count/$limit); 
    } 
    else 
    { 
     $total_pages = 0; 
    } 

    if ($page > $total_pages) 
     $page=$total_pages; 
    $start = $limit*$page - $limit; // Do not put $limit*($page - 1). 
    $SQL = "SELECT school_id, school_name,school_bedge,city,contact, email,typ from school ORDER BY $sidx $sord LIMIT $start , $limit"; 
    $result = mysql_query($SQL) or die("Couldn?t execute query.".mysql_error()); 

    if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) 
    { 
     header("Content-type: application/xhtml+xml;charset=utf-8"); 
    } 
    else 
    { 
     header("Content-type: text/xml;charset=utf-8"); 
    } 
    $et = ">"; 
    echo "<?xml version='1.0' encoding='utf-8'?$et\n"; 
    echo "<rows>"; 
    echo "<page>".$page."</page>"; 
    echo "<total>".$total_pages."</total>"; 
    echo "<records>".$count."</records>"; 

    // Be sure to put text data in CDATA. 
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)) 
    { 
     echo "<row id='". $row[id]."'>"; 
     echo "<cell>". $row['school_id']."</cell>"; 
     echo "<cell>". $row['school_name']."</cell>"; 
     echo "<cell>". $row['city']."</cell>"; 
     echo "<cell>". $row['email']."</cell>"; 
     echo "<cell>". $row['contact']."</cell>"; 
     echo "<cell>". $row['typ']."</cell>"; 
     echo "<cell><![CDATA[". $row[note]."]]></cell>"; 
     echo "</row>"; 
    } 
    echo "</rows>"; 
?> 
+0

Je veux juste une seule ligne de recherche c'est tout ce qui est intégré à la recherche naviguée – Wazan

Répondre

0

Jetez un oeil à les params qui sont envoyés au serveur lorsque vous effectuez une recherche, et modifier votre PHP pour répondre en conséquence. Pas un expert en PHP (j'utilise jqGrid avec Ruby) mais il shoudl être quelque chose le long des lignes de:

if $search="true" { 
    if $name { 
     $where_clause = "where name = $name" 
    } 
} 

$SQL = "SELECT school_id, school_name,school_bedge,city,contact, email,typ from school $where_clause ORDER BY $sidx $sord LIMIT $start , $limit"; 
1

Peut-être le problème est dans votre colonne « Type » où vous utilisez edittype: select. Essayez de remplacer le code suivant:

{name:'type',index:'type', width:80,editable: true, search: false, edittype: 'select', 
       align:"right"},