Molly Molly
Molly Molly

Reputation: 125

Search username with same username in phpmyadmin

Is it able to do search username which exactly same username in phpmyadmin? I mean for example, my database has two cindy, one is cindy, another one is cindy sam. When I search cindy, it only will display cindy, to display cindy sam, i need to search in the text box with cindy sam. Same as alphabet, when key in a, it will not display any data, mean if i want search username, i need to insert complete username stored in database. Hope can understand my question, thank you. And also hope feedback.

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;
}

?>

Upvotes: 1

Views: 75

Answers (1)

JWC May
JWC May

Reputation: 654

Hopes it Work:

   <?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);
     }


    ?>

Upvotes: 1

Related Questions