{"id":7246,"date":"2014-06-03T22:50:12","date_gmt":"2014-06-03T22:50:12","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/unexpected-results-using-pdo-and-or-collection-of-common-programming-errors\/"},"modified":"2014-06-03T22:50:12","modified_gmt":"2014-06-03T22:50:12","slug":"unexpected-results-using-pdo-and-or-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/unexpected-results-using-pdo-and-or-collection-of-common-programming-errors\/","title":{"rendered":"unexpected results using pdo AND OR-Collection of common programming errors"},"content":{"rendered":"<p>I am working on search form with multiple filters ..but having unexpected results M doing it using PDO. and created query based on url&#8230;ursing if,for statements<\/p>\n<p>Url:<code>lType=sale&amp;gender=M|F&amp;loc=can|india|asia<\/code><\/p>\n<pre><code> SELECT * FROM table WHERE 1=1 AND type like :ltype AND location IN (:loca0) OR location IN (:loca1) OR location IN (:loca2) AND gender IN (:gend0) OR gender IN (:gend1)\n<\/code><\/pre>\n<p>so from url we can understand that i want to get results where type=sale (and) gender=m(or)f and Loc=can(or)idnia(or)asia<\/p>\n<p>but not getting results as expected ..<\/p>\n<p>Thanks&#8230;<\/p>\n<p><strong>UPDATE<\/strong><\/p>\n<p>As anwsred by <code>user876345<\/code> i tried to modify my loop to bind locations<\/p>\n<pre><code>if(isset($_GET['loc'])){        \/\/locations\nfor($i=0;$i1 &amp;&amp; count($aloc)!=\"$i\") {    $sqlsl .=\" OR location IN (:loca$i)\";}\nelse if($i&gt;1 &amp;&amp; count($aloc)&gt;1 &amp;&amp; count($aloc)==$i+1) { $sqlsl .=\")\";} \n$bind['loca' . $i] = $aloc[$i];\n}\n} \n<\/code><\/pre>\n<p>but this loop not adding <code>)<\/code> at end if theres more than 1 locations and output<\/p>\n<pre><code>SELECT * FROM table WHERE 1=1 AND (location IN (:loca0) OR location IN (:loca1) OR location IN (:loca2)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am working on search form with multiple filters ..but having unexpected results M doing it using PDO. and created query based on url&#8230;ursing if,for statements Url:lType=sale&amp;gender=M|F&amp;loc=can|india|asia SELECT * FROM table WHERE 1=1 AND type like :ltype AND location IN (:loca0) OR location IN (:loca1) OR location IN (:loca2) AND gender IN (:gend0) OR gender [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7246","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7246"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7246\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}