Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:08:10+00:00 2026-05-31T00:08:10+00:00

I am trying to get the integrated search toolbars working on my page, however

  • 0

I am trying to get the integrated search toolbars working on my page, however I am not having any luck. The regular search function is working for me, but whenever I type anything into the integrated toolbars, it returns 0 results.

Here is my jquery:

$("#parts_table").jqGrid({
            url:'testparts2.php',
            datatype: "json",
            colNames:['Part ID','Name', 'Description', 'Weight'],
            colModel:[
                {name:'part_ID',index:'part_ID', search: true, stype:'text', width:55},
                {name:'part_name',index:'part_name', width:90},
                {name:'part_desc',index:'part_desc', width:100},
                {name:'part_weight',index:'part_weight', width:80, align:"right"},      
            ],
            rowNum:30,
            rowList:[10,20,30],
            pager: '#pager2',
            sortname: 'part_ID',
            viewrecords: true,
            sortorder: "asc",
            caption:"Parts in Database",
            width: '800',
            height: '300',
        });
        $("#parts_table").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
        $("#parts_table").jqGrid('filterToolbar',{stringResult: false,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});

and here is my PHP code:

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

    //array to translate the search type
    $ops = array(
        'eq'=>'=', //equal
        'ne'=>'<>',//not equal
        'lt'=>'<', //less than
        'le'=>'<=',//less than or equal
        'gt'=>'>', //greater than
        'ge'=>'>=',//greater than or equal
        'bw'=>'LIKE', //begins with
        'bn'=>'NOT LIKE', //doesn't begin with
        'in'=>'LIKE', //is in
        'ni'=>'NOT LIKE', //is not in
        'ew'=>'LIKE', //ends with
        'en'=>'NOT LIKE', //doesn't end with
        'cn'=>'LIKE', // contains
        'nc'=>'NOT LIKE'  //doesn't contain
    );
    function getWhereClause($col, $oper, $val){
        global $ops;
        if($oper == 'bw' || $oper == 'bn') $val .= '%';
        if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
        if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
        return " WHERE $col {$ops[$oper]} '$val' ";
    }
    $where = ""; //if there is no search request sent by jqgrid, $where should be empty
    $searchField = isset($_GET['searchField']) ? $_GET['searchField'] : false;
    $searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: false;
    $searchString = isset($_GET['searchString']) ? $_GET['searchString'] : false;
    if ($_GET['_search'] == 'true') {
        $where = getWhereClause($searchField,$searchOper,$searchString);
    }   

    $totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
    if($totalrows) {
        $limit = $totalrows;
    }

    $result = mysql_query("SELECT COUNT(*) AS count FROM parts");
    $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;
    if ($limit<0) $limit = 0;
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    if ($start<0) $start = 0;
    $SQL = "SELECT * FROM parts ".$where." ORDER BY $sidx $sord LIMIT $start , $limit";
    $result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
    $response->page = $page;
    $response->total = $total_pages;
    $response->records = $count;
    $i=0;
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
        $response->rows[$i]['part_ID']=$row[part_ID];
        $response->rows[$i]['cell']=array($row[part_ID],$row[part_name],$row[part_desc],$row[part_weight]);
        $i++;
    } 
    echo json_encode($response);

?>

It took me hours of searching to find a PHP example that worked for regular searching (see above), however it doesn’t seem to work for the toolbar searching. Can anyone help? Thanks

edit: Here is code from jqGrid’s demo folder for using this search, but it appears to be full of errors and I have no idea how to use it for my case. I don’t need to specify data type for the searches (they are all varchars, so strings will work fine)..so I think that I can strip out the switch/case part for value conversion. I think I just need to change my original code to use $_REQUEST['filters'] and a foreach loop to build the query, but I’m not that great with PHP so any help is appreciated.

demo code:

$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
    $searchstr = Strip($_REQUEST['filters']);
    $wh= constructWhere($searchstr);
    //echo $wh;
}
function constructWhere($s){
    $qwery = "";
    //['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
    $qopers = array(
                  'eq'=>" = ",
                  'ne'=>" <> ",
                  'lt'=>" < ",
                  'le'=>" <= ",
                  'gt'=>" > ",
                  'ge'=>" >= ",
                  'bw'=>" LIKE ",
                  'bn'=>" NOT LIKE ",
                  'in'=>" IN ",
                  'ni'=>" NOT IN ",
                  'ew'=>" LIKE ",
                  'en'=>" NOT LIKE ",
                  'cn'=>" LIKE " ,
                  'nc'=>" NOT LIKE " );
    if ($s) {
        $jsona = json_decode($s,true);
        if(is_array($jsona)){
            $gopr = $jsona['groupOp'];
            $rules = $jsona['rules'];
            $i =0;
            foreach($rules as $key=>$val) {
                $field = $val['field'];
                $op = $val['op'];
                $v = $val['data'];
                if($v && $op) {
                    $i++;
                    // ToSql in this case is absolutley needed
                    $v = ToSql($field,$op,$v);
                    if ($i == 1) $qwery = " AND ";
                    else $qwery .= " " .$gopr." ";
                    switch ($op) {
                        // in need other thing
                        case 'in' :
                        case 'ni' :
                            $qwery .= $field.$qopers[$op]." (".$v.")";
                            break;
                        default:
                            $qwery .= $field.$qopers[$op].$v;
                    }
                }
            }
        }
    }
    return $qwery;
}
function ToSql ($field, $oper, $val) {
    // we need here more advanced checking using the type of the field - i.e. integer, string, float
    switch ($field) {
        case 'id':
            return intval($val);
            break;
        case 'amount':
        case 'tax':
        case 'total':
            return floatval($val);
            break;
        default :
            //mysql_real_escape_string is better
            if($oper=='bw' || $oper=='bn') return "'" . addslashes($val) . "%'";
            else if ($oper=='ew' || $oper=='en') return "'%" . addcslashes($val) . "'";
            else if ($oper=='cn' || $oper=='nc') return "'%" . addslashes($val) . "%'";
            else return "'" . addslashes($val) . "'";
    }
}

$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id".$wh);
        $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)
        if ($start<0) $start = 0;
        $SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
        $result = mysql_query( $SQL ) or die("Could not execute query.".mysql_error());
        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
        $i=0;
        while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
            $responce->rows[$i]['id']=$row[id];
            $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
            $i++;
        } 
        //echo $json->encode($responce); // coment if php 5
        echo json_encode($responce);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:08:11+00:00Added an answer on May 31, 2026 at 12:08 am

    I actually just had this same problem myself yesterday. You are correct, you need to bring in the filters using $_REQUEST[‘filters’] and then break it up so that you can use each piece.

    First, you are going to need to set stringResult: true in your jQuery file where you initialize the FilterToolbar.

    Here is the code that PHP will use to bring in, and break up the filters object:

    // Gets the 'filters' object from JSON
    $filterResultsJSON = json_decode($_REQUEST['filters']);
    
    // Converts the 'filters' object into a workable Array
    $filterArray = get_object_vars($filterResultsJSON);
    

    Now that you have $filterArray containing the contents of the filters object, you can now break up the rules object which is contained inside. Basically, there is another array inside the $filterArray which contains the search details if the user tries performing this search across multiple columns in their table – it’s called rules.

    Here is how I break up the rules object and perform a SELECT query based on the user’s input:

    // Begin the select statement by selecting cols from tbl
    $sql = 'select '.implode(',',$crudColumns).' from '.$crudTableName;
    // Init counter to 0
    $counter = 0;
    // Loop through the $filterArray until we process each 'rule' array inside
    while($counter < count($filterArray['rules']))
    {
    // Convert the each 'rules' object into a workable Array
    $filterRules = get_object_vars($filterArray['rules'][$counter]);
    
    // If this is the first pass, start with the WHERE clause
    if($counter == 0){
    $sql .= ' WHERE ' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
    }
    // If this is the second or > pass, use AND
    else {
    $sql .= ' AND ' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
    }
    $counter++;
    }
    
    // Finish off the select statement
    $sql .= ' ORDER BY ' . $postConfig['sortColumn'] . ' ' . $postConfig['sortOrder']; 
    $sql .= ' LIMIT '.$intStart.','.$intLimit;
    
    /* run the query */
    $result = mysql_query( $sql )
    

    I’m sure you’ll have questions, so feel free to ask if you do!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a record but I get an exception. Any ideas? private
trying to get some data from a plist into the MWPhotoBrowser sample app. Any
Trying to get an ASP application deployed; it worked for a while but then
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm trying to fix a bug with a site search function and have isolated
I am trying the websharper demonstrations, however I get the following error:- HTTP Error
I'm trying to get rid of the /reports directory which seems to be integrated
I’ve been trying to get this to work for a while but can’t (I
I'm trying to get an ASP.NET MVC app working... I should have known it
I am working on an ASP.NET MVC project and I am trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.