<?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: PHP Code for building SQL Search Query (where clause)</title>
	<link>http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause</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/discussion/php-code-for-building-sql-search-query-where-clause/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>marktees on PHP Code for building SQL Search Query (where clause)</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p22535</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p22535</guid>
        	        	<description><![CDATA[<blockquote>
<p>waseem said:</p>
<p>Great Dude nice function but before that how to post the values from jqgrid? plz m stuK?????<img class="spSmiley" style="margin:0" title="Cry" src="/blog/wp-content/forum-smileys/sf-cry.gif" alt="Cry" /></p>
</blockquote>
<hr />
<p>Hey, make sure you are using something like Firebug so you can get a good view of whats happening.</p>
<p>By default as soon as I had the pager there and I could see the search button when I clicked find (with some parameters) it POSTED like this:</p>
</p>
<table class="netInfoParamsText netInfoText netInfoParamsTable " border="0" cellspacing="0" cellpadding="0">
<tbody class=" ">
<tr class=" ">
<td class="netInfoParamName ">_search</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit5229' value='Select Code' data-codeid='sfcode5229' /></p>
<div class='sfcode' id='sfcode5229'>true</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">nd</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit5684' value='Select Code' data-codeid='sfcode5684' /></p>
<div class='sfcode' id='sfcode5684'>1300921202001</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">page</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit3932' value='Select Code' data-codeid='sfcode3932' /></p>
<div class='sfcode' id='sfcode3932'>1</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">rows</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit3781' value='Select Code' data-codeid='sfcode3781' /></p>
<div class='sfcode' id='sfcode3781'>10</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">searchField</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit8229' value='Select Code' data-codeid='sfcode8229' /></p>
<div class='sfcode' id='sfcode8229'>id</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">searchOper</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit1589' value='Select Code' data-codeid='sfcode1589' /></p>
<div class='sfcode' id='sfcode1589'>eq</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">searchString</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit4153' value='Select Code' data-codeid='sfcode4153' /></p>
<div class='sfcode' id='sfcode4153'>8</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">sidx</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit6182' value='Select Code' data-codeid='sfcode6182' /></p>
<div class='sfcode' id='sfcode6182'>id</div>
</td>
</tr>
<tr class=" ">
<td class="netInfoParamName ">sord</td>
<td class="netInfoParamValue ">
<p><input type='button' class='sfcodeselect' name='sfselectit1272' value='Select Code' data-codeid='sfcode1272' /></p>
<div class='sfcode' id='sfcode1272'>desc</div>
</td>
</tr>
</tbody>
</table>
]]></description>
        	        	<pubDate>Thu, 24 Mar 2011 01:05:13 +0200</pubDate>
        </item>
        <item>
        	<title>waseem on PHP Code for building SQL Search Query (where clause)</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p8730</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p8730</guid>
        	        	<description><![CDATA[<p>Great Dude nice function but before that how to post the values from jqgrid? plz m stuK?????<img class="spSmiley" style="margin:0" title="Cry" src="/blog/wp-content/forum-smileys/sf-cry.gif" alt="Cry" /></p>
]]></description>
        	        	<pubDate>Tue, 18 Aug 2009 05:08:49 +0300</pubDate>
        </item>
        <item>
        	<title>paul on PHP Code for building SQL Search Query (where clause)</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p8713</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/php-code-for-building-sql-search-query-where-clause#p8713</guid>
        	        	<description><![CDATA[<p>Here&#39;s a code snippet for PHP for building SQL an search query (where clause) from the jqGRID params.</p>
<p>I&#39;m not sure if this is the best/most efficient way to do this, but since I couldn&#39;t find code for doing this in the documentation anywhere, I&#39;m posting what I&#39;m doing.</p>
<p>I keep an array of the operators sent from jqGrid, and use a function to  return the WHERE clause associated with it. I&#39;m assuming that &#39;contains&#39; and &#39;is in&#39; mean the same thing, which is probably not what Tony meant. It&#39;s easy to change the mapping though, so feel free to do so.</p>
</p>
<pre>$ops = array(
    &#39;eq&#39;=&#62;&#39;=&#39;, //equal
    &#39;ne&#39;=&#62;&#39;&#60;&#62;&#39;,//not equal
    &#39;lt&#39;=&#62;&#39;&#60;&#39;, //less than
    &#39;le&#39;=&#62;&#39;&#60;=&#39;,//less than or equal
    &#39;gt&#39;=&#62;&#39;&#62;&#39;, //greater than
    &#39;ge&#39;=&#62;&#39;&#62;=&#39;,//greater than or equal
    &#39;bw&#39;=&#62;&#39;LIKE&#39;, //begins with
    &#39;bn&#39;=&#62;&#39;NOT LIKE&#39;, //doesn&#39;t begin with
    &#39;in&#39;=&#62;&#39;LIKE&#39;, //is in
    &#39;ni&#39;=&#62;&#39;NOT LIKE&#39;, //is not in
    &#39;ew&#39;=&#62;&#39;LIKE&#39;, //ends with
    &#39;en&#39;=&#62;&#39;NOT LIKE&#39;, //doesn&#39;t end with
    &#39;cn&#39;=&#62;&#39;LIKE&#39;, // contains
    &#39;nc&#39;=&#62;&#39;NOT LIKE&#39;  //doesn&#39;t contain
);   
/**
* Returns SQL WHERE clause
* @param string $col sql column name
* @param string $oper operator from jqGrid
* @param string $val value (right hand side)
*/
function getWhereClause($col, $oper, $val){
    global $ops;    
    if($oper == &#39;bw&#39; &#124;&#124; $oper == &#39;bn&#39;) $val .= &#39;%&#39;;
    if($oper == &#39;ew&#39; &#124;&#124; $oper == &#39;en&#39; ) $val = &#39;%&#39;.$val;
    if($oper == &#39;cn&#39; &#124;&#124; $oper == &#39;nc&#39; &#124;&#124; $oper == &#39;in&#39; &#124;&#124; $oper == &#39;ni&#39;) $val = &#39;%&#39;.$val.&#39;%&#39;;
    return " AND $col {$ops[$oper]} &#39;$val&#39; ";
}

</pre>
<p>Obviously, you&#39;ll need to get the search params from the $_GET array. I do something like this:</p>
<pre>$searchField = isset($_GET[&#39;searchField&#39;]) ? $_GET[&#39;searchField&#39;] : false; 
$searchOper = isset($_GET[&#39;searchOper&#39;]) ? $_GET[&#39;searchOper&#39;]: false;  
$searchString = isset($_GET[&#39;searchString&#39;]) ? $_GET[&#39;searchString&#39;] : false;
</pre>
</p>
<p>Then the query is simply: &#8220;SELECT * FROM $searchField &#8220;. getWhereClause($searchField,$searchOper,$searchString);</p>
<p>-paul</p></p>
]]></description>
        	        	<pubDate>Mon, 17 Aug 2009 11:19:01 +0300</pubDate>
        </item>
</channel>
</rss>