不区分大小写但敏感

时间:2016-10-25 17:33:27

标签: php mysql search case-sensitive case-insensitive

这是我的数据库:database

那两行rows

当我试图找到" CEC" in" banca"行,一切正常(用CEC banca显示我的行)。如果我试图找到" cec"或者" Cec"或" ceC" in" banca"排,没有结果,我不知道为什么! 如果我提交确切的" TEXT"我不想要那个。

那是PHP代码:

$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM fachitate WHERE CONCAT (ID, data, furnizor, suma, banca, firma, observatii) LIKE '%".$valueToSearch."%'" ;
$search_result = filterTable($query);

// function to connect and execute the query

    function filterTable($query)
    {
        $connect = mysqli_connect("localhost", "root", "MYPASS", "facturi_db");
        $filter_Result = mysqli_query($connect, $query);
        return $filter_Result;
    }


echo "<table>
<tr>
<th>ID</th>
<th>Data</th>
<th>Furnizor</th>
<th>Suma</th>
<th>Banca</th>
<th>Firma</th>
<th>Observatii</th>
</tr>";
while($row = mysqli_fetch_array($search_result))
  {
    echo "<td><font color='#000000'>" . $row['ID'] . "</td>";
    echo "<td><font color='#000000'>" . $row['data'] . "</td>";
    echo "<td><font color='#000000'>" . $row['furnizor'] . "</td>";
    echo "<td><font color='#000000'>" . $row['suma'] . "</td>";
    echo "<td><font color='#000000'>" . $row['banca'] . "</td>";
    echo "<td><font color='#000000'>" . $row['firma'] . "</td>";
    echo "<td><font color='#000000'>" . $row['observatii'] . "</td>";

  echo "</tr>";
    }

形式:

    <form action="myfilter.php" method="post">
        <input type="text" name="valueToSearch" placeholder="Adauga nou filtru">
        <input type="submit" name="search" value="Filtreaza"><br><br>
     </form>

请帮忙! 谢谢!

1 个答案:

答案 0 :(得分:0)

像这样更新你的选择:

$query = "SELECT * FROM fachitate WHERE LOWER(CONCAT(ID, data, furnizor, suma, banca, firma, observatii)) LIKE '%".strtolower($valueToSearch)."%'" ;

如果您将搜索关键字和搜索字词转换为小写,则案例会变得不敏感;)