Q:

Search function in ajax not working due to failing where statement

I'm doing a table with sort, page and search function.First of all, the code runs well, but after I added where in my sql, the search function doesn't work anymore.
<?php

include_once("connection.php");
 session_start();

$db = new dbObj();
$connString =  $db->getConnstring();

$params = $_REQUEST;

$action = isset($params['action']) != '' ? $params['action'] : '';
$empCls = new cusinfo($connString);

switch($action) 
{
 default:
 $empCls->getEmployees($params);
 return;
}

class cusinfo 
{
protected $conn;
protected $data = array();
function __construct($connString) 
{
    $this->conn = $connString;
}

public function getEmployees($params) 
{
    $this->data = $this->getRecords($params);
    echo json_encode($this->data);
}

function getRecords($params) {

    $rp = isset($params['rowCount']) ? $params['rowCount'] : 10;

    if (isset($params['current'])) { $page  = $params['current']; } else { $page=1; };  
    $start_from = ($page-1) * $rp;

    $sql = $sqlRec = $sqlTot = $where = '';

    if( !empty($params['searchPhrase']) ) 
    {   
        $where .=" WHERE ";
        $where .=" ( NO_ID LIKE '".$params['searchPhrase']."%' ";    
        $where .=" OR TICKET_ID LIKE '".$params['searchPhrase']."%' ";
        $where .=" OR CAT_C_B LIKE '".$params['searchPhrase']."%' ";
        $where .=" OR ORDER_TYPE LIKE '".$params['searchPhrase']."%' ";
        $where .=" OR AGENT_STAFF_NAME LIKE '".$params['searchPhrase']."%' ";
        $where .=" OR EFORM_ID LIKE '".$params['searchPhrase']."%' ";
        $where .=" OR LATEST_ORDER_STATUS LIKE '".$params['searchPhrase']."%' )";
   }
   if( !empty($params['sort']) ) 
    {  
        $where .=" ORDER By ".key($params['sort']) .' '.current($params['sort'])." ";
    }
   // getting total number records without any search
    $role = $_SESSION['sess_userrole'];
    $uid = $_SESSION['sess_user_id'];
    $tid = $_SESSION['tmid'];
    $mid = $_SESSION['mid'];
    $sid = $_SESSION['sid'];

    if($role=="admin")
{           
    $sql = "SELECT * FROM `cusinfo` where AGENT_CODE_STAFF_ID IN (SELECT id FROM `users` where tm_groupid = '$tid') ";
    $sqlTot .= $sql;
    $sqlRec .= $sql;
}
else
{
    .
    .
    .
}

    //concatenate search sql if value exist
    if(isset($where) && $where != '') 
    {
        $sqlTot .= $where;
        $sqlRec .= $where;
    }
    if ($rp!=-1)
    $sqlRec .= " LIMIT ". $start_from .",".$rp;

    $qtot = mysqli_query($this->conn, $sqlTot) or die("error to fetch tot customer data");
    $queryRecords = mysqli_query($this->conn, $sqlRec) or die("error to fetch customer data");

    while( $row = mysqli_fetch_assoc($queryRecords) ) 
    { 
        $data[] = $row;
    }

    $json_data = array(
        "current"       => $page, 
        "rowCount"      => 10,          
        "total"         => intval($qtot->num_rows),
        "rows"          => $data   // total data array
        );

    return $json_data;
}
}
?>

A:

Thankyou for all of the reply,this question have been solve by myself.It can be solve by just change the where to AND on the code bellow:
 if( !empty($params['searchPhrase']) ) 
{   
    $where .=" WHERE";//change this line to $where .=" AND";
.
.
.
}

