2011-02-19 131 views
0

這是我的代碼。我的搜索不起作用,Edit正在顯示,但沒有保存到數據庫中!我嘗試了這個URL,http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3asinge_searching。但我無法糾正它。我該如何解決這個問題?jqGrid搜索不起作用

<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> 

我的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

我只想單行搜索這就是所有與導航搜索集成在一起 – Wazan 2011-02-19 05:33:41

回答

0

看看,當你做一個搜索被髮送到服務器的參數,可以修改您的PHP作出相應的反應。不是PHP高手(我使用的jqGrid與紅寶石),但它shoudl是沿着線的東西:

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

可能問題是出在你的「類型」列在您使用edittype: select。嘗試用替換下面的代碼:

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