在phpmyadmin中使用相同的用户名搜索用户名

时间:2017-12-05 03:33:37

标签: php

能否在phpmyadmin中搜索用户名完全相同的用户名?我的意思是,例如,我的数据库有两个cindy,一个是cindy,另一个是cindy sam。当我搜索cindy时,它只显示cindy,显示cindy sam,我需要在cindy sam的文本框中搜索。与字母相同,当键入a时,它不会显示任何数据,意味着如果我想要搜索用户名,我需要插入存储在数据库中的完整用户名。希望能理解我的问题,谢谢。并希望得到反馈。

PHP:

<?php

if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `table1` WHERE CONCAT(`username`) 
LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);

 }
 else {
 $query = "SELECT * FROM `table1` LIMIT 0";
 $search_result = filterTable($query);
 }

 // function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "wp");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>

1 个答案:

答案 0 :(得分:1)

希望它有效:

   <?php

      // function to connect and execute the query
        function filterTable($query)
        {
        $connect = mysqli_connect("localhost", "root", "", "wp");
        $filter_Result = mysqli_query($connect, $query);
        return $filter_Result;
        }

    if(isset($_POST['search']))
    {
        $valueToSearch = $_POST['valueToSearch'];

     $query = "select * from table1 where CONCAT(username) like '%$valueToSearch%' LIMIT 0,500";
                    $search_result = filterTable($query);
    }
    else
     {
     $query = "SELECT * FROM table1 LIMIT 0";
     $search_result = filterTable($query);
     }


    ?>