Hello,
Performing full text or tolerant searches with the following code when using MySQLi
Text only to search with tolerances: word
To search for full text, use double quotes to search: "word"
$search_keyword = $_POST['query'];
$pattern = '/^".+"$/i';
if(preg_match($pattern, $search_keyword)){
$search_keyword = str_replace('"','',$search_keyword);
$search_keyword = " '$search_keyword' ";
}else{
$search_keyword = " '%$search_keyword%' ";
}
Now I switched to PDO
I want to include the above code in the query code below
Could you help
if(isset($_POST['per'])){
$limit = $_POST['per'];
}
else
{
$limit = '10';
}
$search_keyword = '';
if(!empty($_POST['query'])) {
$search_keyword = $_POST['query'];
}
$sql = 'SELECT
teklifler.id,
teklifler.teklif_no,
teklifler.teklif_tarihi,
teklifler.members_id,
teklifler.members_group,
teklifler.firma_yetkili_adi_soyadi,
teklifler.pdf_dosya_adi,
teklifler.secilen_parabirimi_id,
teklifler.musteri_bilgileri_json,
teklifler.firma_bilgileri_json,
teklifler.siparis_durumu,
members.members_group,
members.firma_adi,
members.firma_yetkili_adi_soyadi,
members.firma_emaili
FROM teklifler
INNER JOIN members ON teklifler.members_id = members.members_id
WHERE
teklifler.teklif_no LIKE :keyword OR
teklifler.teklif_tarihi LIKE :keyword OR
teklifler.musteri_bilgileri_json LIKE :keyword OR
teklifler.members_id LIKE :keyword OR
teklifler.siparis_durumu LIKE :keyword OR
members.firma_adi LIKE :keyword OR
members.firma_yetkili_adi_soyadi LIKE :keyword OR
members.firma_emaili LIKE :keyword
ORDER BY teklifler.id DESC ';
$page = 1;
$start = 0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start = ($page-1) * $limit;
}
$limit_code = " LIMIT " . $start . "," . $limit;
$pagination_statement = $PDOdatabase->prepare($sql);
$pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pagination_statement->execute();
$total_page = $pagination_statement->rowCount();
$query = $sql.$limit_code;
$pdo_statement = $PDOdatabase->prepare($query);
$pdo_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();