I am facing some problem, when trying to fetching data or username from two table in same query. the code is given below. Whats wrong with that code. I have sat UNION, UNION ALL etc. But still it is not working. Usually by putting one table, the query show result, but after putting two table in $sql is does not show any result.
$username = "";
$code = "";
$queryCondition = "";
if(!empty($_POST["search"])) {
    foreach($_POST["search"] as $k=>$v){
        if(!empty($v)) {
            $queryCases = array("username","code");
            if(in_array($k,$queryCases)) {
                if(!empty($queryCondition)) {
                    $queryCondition .= " AND ";
                } else {
                    $queryCondition .= " WHERE ";
                }
            }
            switch($k) {
                case "username":
                    $username = $v;
                    $queryCondition .= "username LIKE '%" . $v . "%'";
                    break;
                case "code":
                    $code = $v;
                    $queryCondition .= "code LIKE '%" . $v . "%'";
                    break;
            }
        }
    }
}
$orderby = " ORDER BY added desc"; 
$sql = "SELECT * FROM tableA OR SELECT * from tableB ORDER BY added" . 
$queryCondition;
$href = 'abcd.php';                 
$perPage = 5; 
$page = 1;
if(isset($_POST['page'])){
    $page = $_POST['page'];
}
$start = ($page-1)*$perPage;
if($start < 0) $start = 0;
$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
$result = $db_handle->runQuery($query);
if(!empty($result)) {
    $result["perpage"] = showperpage($sql, $perPage, $href);
}
?>
<div id="toys-grid">      
        <form name="frmSearch" method="post" action="list.php">
        <div class="search-box">
        <p><input type="text" placeholder="username" name="search[username]" class="demoInputBox" value="<?php echo $username; ?>"  />
        <input type="text" placeholder="Code" name="search[code]" class="demoInputBox" value="<?php echo $code; ?>" />
        <input type="submit" name="go" class="btnSearch" value="Search">
        <input type="reset" class="btnSearch" value="Reset" onclick="window.location='list.php'"></p>
        </div>
<div class="not">
<?php
        foreach($result as $k=>$v) {
        if(is_numeric($k)) {
        ?>
 <div  class="" > 
  <div class="testimonial" >
  <h4><a href="<?php echo $result[$k]["link"]; ?>"><?php echo $result[$k]["username"]; ?></a></h4>
  <img src="<?php echo $result[$k]["image"]; ?>" style="width:100px;height:100px;">
  <p style=""><?php echo $result[$k]["usertype"]; ?></p>
  <div class="textads-link">
  <strong>http://btcgenuis.com</strong><br>
  <p><?php echo $result[$k]["regdate"]; ?></p>
  </div>
  </div> 
  </div>    
 <?php
        }
    }?>
 </div><div style="clear: both; height: 10px"></div>  <div style="text-align:right;margin:20px 0px 10px;">  
                <?php
                if(isset($result["perpage"])) {
                ?>
                 <?php echo $result["perpage"]; ?>
                <?php } ?>
        </div>
        </form>  
Hope so get a best solution for this error.
 
    