php和mysql搜索用户

I wrote this code to search users from mysql :

$query = $db->query("SELECT * FROM `users` WHERE `id` = {$id} ");
while($row = $query->fetch_assoc()){
    echo $row['username'];
    // ....
    echo "People also search :";
    // the people also search box
}

I want it so that when the user pages load in the bottom of the page be a box like this:

Walter

...

People also search :

Bruce Kevin Jesse

something like the Google when you search actors or ...

how could I do this ?

You'd need to keep a record of past searches and then when a new one is searched find all the people who searched for that in the past and find what else they searched for.

why don't you start by getting it to work with some random values from the database response

$query = $db->query("SELECT username FROM `users");
while($row = $query->fetch_assoc()){
     $rows[]=$row
}
//id of the user by which you have made the search
echo $rows[$id];
unset($rows[$id]);
echo "People also search :".PHP_EOL;
$rand_keys = array_rand($rows, 5);
foreach($rand_keys as $key){
    echo $rows[$key];
}