I have a table with multiple columns (11 columns appox.) with seach bar, I need the search to be capable to search any string in all columns(ex. search 2 words in two columns...)
I'm using mysqli PDO connection with Jquery, ajax, PHP
I have tried the below but serching for exact search for the first word and so on
My connection:
public function __construct()
{
try {
$dsn = "mysql:host={$this->dbServer}; dbname={$this->dbName}; charset=utf8";
$options = array(PDO::ATTR_PERSISTENT);
$this->conn = new PDO($dsn, $this->dbUser, $this->dbPassword, $options);
} catch (PDOException $e) {
echo "Connection Error: " . $e->getMessage();
}
}
fetch data file:
public function searchdoctor($searchText, $start = 0, $limit = 100)
{
$sql = "SELECT * FROM {$this->tableName}
WHERE CONCAT(doctor,' ',facility) LIKE :search
ORDER BY id DESC LIMIT {$start},{$limit}";
$stmt = $this->conn->prepare($sql);
$stmt->execute([':search' => "%{$searchText}%"]);
if ($stmt->rowCount() > 0) {
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
} else {
$results = [];
}
return $results;
}