title: MySQL Query using UNION - PHP PDO issues
body: <p>I have built a basic search engine which is almost functional. I am using <code>UNION</code> in the query in order to search for an specific value in two tables <code>blog</code> and <code>pages</code>. I am also using PDO style. There are a total of 13 rows. When I perform the query with keyword <code>blah</code> which is found in every column of both tables. I only get 5 results back from <code>SELECT COUNT(*) FROM blog</code>  and nothing back from <code>SELECT COUNT(*) FROM pages</code> . Also I am using a prepare statement for <code>:searchquery =&gt; $serachquery</code> that stores the keyword value but when echoing the value I get <code>:searchquery</code> instead of <code>blah</code>. How can I display the correct results? <a href="http://holaweblearning.co.nf/test/search2.php" rel="nofollow">DEMO</a></p>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  include("db_con/db_con.php");
  $search_output = "";
  if(isset($_POST['searchquery']) &amp;&amp; $_POST['searchquery'] != ""){
    $searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']);
    if($_POST['filter1'] == "All Tables"){
     $sqlCommand = "(SELECT COUNT(*) FROM blog WHERE blog_title LIKE :searchquery OR blog_body LIKE :searchquery) UNION (SELECT COUNT(*) FROM pages WHERE page_title LIKE :searchquery OR page_body LIKE :searchquery) ";
    }
    $sql_prepare = $db_con-&gt;prepare($sqlCommand);
    if($sql_prepare-&gt;execute( array("searchquery"=&gt;'%'.$searchquery.'%') )){
      $count = $sql_prepare-&gt;fetchColumn();
      if($count &gt; 1){
        $search_output .= "&lt;hr /&gt;$count results for &lt;strong&gt;$searchquery&lt;/strong&gt;&lt;hr /&gt;$sqlCommand";
      } else {
        $search_output = "&lt;hr /&gt;0 results for &lt;strong&gt;$searchquery&lt;/strong&gt;$sqlCommand&lt;hr /&gt;";
      }
    }
  }
  ?&gt;
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
  Search For:
    &lt;input name="searchquery" type="text" size="44" maxlength="88"&gt;
  Within:
  &lt;select name="filter1"&gt;
  &lt;option value="All Tables"&gt;All Tables&lt;/option&gt;
  &lt;/select&gt;
  &lt;input name="myBtn" type="submit"&gt;
  </code></pre>